List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider
public BouncyCastleProvider()
From source file:com.vvote.verifierlibrary.utils.crypto.CryptoUtils.java
License:Open Source License
/** * Adds the BouncyCastle Security Provider. May be called multiple times *///from w w w .ja v a2s . com public static void initProvider() { if (!providerAdded) { logger.debug("Adding BouncyCastle provider"); Security.addProvider(new BouncyCastleProvider()); providerAdded = true; PairingFactory.getInstance().setUsePBCWhenPossible(true); } }
From source file:com.wandrell.util.ksgen.KeyStoreGenerator.java
License:Open Source License
/** * Runs the generator and creates a new set of key stores. * * @param args//from w ww .j a v a 2s . c o m * the arguments * @throws Exception * if any problem occurs while generating the key stores */ public static final void main(final String[] args) throws Exception { final KeyStore jksMain; // Main key store final KeyStore jksSecond; // Second key store final KeyStore jceksSym; // Symmetric key store final String jksMainPath; // Path for the main key store final String jksSecondPath; // Path for the second key store final String jceksSymPath; // Path for the symmetric key store final String password; // Password to apply to the key stores final String alias; // Alias for the certificate final String issuer; // Issuer for the certificate final KeyStoreFactory factory; // KS factory factory = new BouncyCastleKeyStoreFactory(); jksMainPath = "src/main/resources/keystore.jks"; jksSecondPath = "src/main/resources/keystore2.jks"; jceksSymPath = "src/main/resources/symmetric.jceks"; password = "123456"; alias = "swss-cert"; issuer = "CN=www.wandrell.com, O=Wandrell, OU=None, L=London, ST=England, C=UK"; Security.addProvider(new BouncyCastleProvider()); // Main key store LOGGER.trace("Creating main key store"); jksMain = factory.getJavaKeyStore(password, alias, issuer); // Saves the main keystore saveToFile(jksMain, jksMainPath, password.toCharArray()); LOGGER.trace("Created main key store"); // Second key store LOGGER.trace("Creating second key store"); jksSecond = factory.getJavaKeyStore(password, alias, issuer); // Saves the second key store saveToFile(jksSecond, jksSecondPath, password.toCharArray()); LOGGER.trace("Created second key store"); // Symmetric key store LOGGER.trace("Creating symmetric key store"); jceksSym = factory.getJavaCryptographicExtensionKeyStore(password, alias); // Saves the symmetric key store saveToFile(jceksSym, jceksSymPath, password.toCharArray()); LOGGER.trace("Created symmetric key store"); LOGGER.trace("Finished creating key stores"); }
From source file:com.wlami.mibox.client.application.MiboxClientApp.java
License:Open Source License
/** * Main entry point for the MiboxClientApplication. * /*from ww w.ja v a2 s. co m*/ * @param args * no command line arguments needed. * @throws IOException * thrown, if app properties cannot be loaded. */ public static void main(final String[] args) throws IOException { log.info("Startup mibox client."); Security.addProvider(new BouncyCastleProvider()); ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); MiboxClientApp miboxClientApp = ctx.getBean("miboxClientApp", MiboxClientApp.class); miboxClientApp.run(); }
From source file:com.worldpay.cse.WorldpayCSETest.java
License:Open Source License
@Before public void before() throws Exception { //Java 7 does not support a set of new encryption algorithms such as AES256GCM if (Security.getProvider("BC") == null) { Security.addProvider(new BouncyCastleProvider()); }//from ww w .ja va2 s .com worldpayCSE = new WorldpayCSE(); }
From source file:com.yosanai.java.swing.config.FileBackedConfigDialog.java
License:Open Source License
public void init(String... keys) { if (null == configuration) { ConfigPasswordDialog dialog = new ConfigPasswordDialog(null, true); StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); if (null == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)) { Security.insertProviderAt(new BouncyCastleProvider(), 1); }/*from w w w. j ava 2 s. c o m*/ encryptor.setAlgorithm(DEFAULT_ALGORITHM); dialog.setEncryptor(encryptor); dialog.setVisible(true); if (ConfigPasswordDialog.RET_OK == dialog.getReturnStatus()) { try { configuration = new EncryptedXMLConfiguration(encryptor); configuration.setFileName(file); configuration.load(file); } catch (ConfigurationException e) { try { String defaultPath = System.getProperty("user.home") + "/" + file; new File(defaultPath).createNewFile(); FileInputStream ins = new FileInputStream(defaultPath); String entries = IOUtils.toString(ins); IOUtils.closeQuietly(ins); if (StringUtils.isBlank(entries)) { configuration = new EncryptedXMLConfiguration(encryptor); configuration.setFileName(defaultPath); try { configuration.save(); } catch (ConfigurationException cfEx) { Logger.getLogger(FileBackedConfigDialog.class.getName()).log(Level.SEVERE, null, cfEx); } } } catch (IOException ioEx) { Logger.getLogger(FileBackedConfigDialog.class.getName()).log(Level.SEVERE, null, ioEx); } } } } if (null != configuration) { configuration.setAutoSave(true); load(keys); } }
From source file:com.zotoh.crypto.Crypto.java
License:Open Source License
private Crypto() { Security.addProvider(_prov = new BouncyCastleProvider()); }
From source file:com.zotoh.crypto.Crypto.java
License:Open Source License
@SuppressWarnings("unused") private static void main(String[] args) { try {/* ww w. jav a 2 s . c o m*/ // test code KeyStore ks = KeyStore.getInstance("PKCS12", new BouncyCastleProvider()); ks.load(CoreUte.rc2Stream("com/zotoh/crypto/zotoh.p12"), "Password1".toCharArray()); String nm = ks.aliases().nextElement(); PrivateKeyEntry k = (PrivateKeyEntry) ks.getEntry(nm, new PasswordProtection("Password1".toCharArray())); ks = KeyStore.getInstance("JKS"); ks.load(null, null); ks.setKeyEntry(nm, k.getPrivateKey(), "Password1".toCharArray(), k.getCertificateChain()); ks.store(new FileOutputStream("w:/zotoh.jks"), "Password1".toCharArray()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.zxy.commons.codec.rsa.AbstractRSABcUtils.java
License:Apache License
public AbstractRSABcUtils() { Security.addProvider(new BouncyCastleProvider()); }
From source file:controlador.ControlEmpleados.java
/** * Solicita al server la SecretKey para cifrar/descifrar el resto de la comunicacin. Primero, hace una * peticin http de cuya respuesta abre un InputStream y almacena el stream de bytes en un fichero binario. * Este fichero es la clave pblica del servidor y se utilizar para descifrar asimtricamente la segunda * peticin, la cual contiene un objeto SecretKey que ser el utilizado para cifrar/descifrar de manera simtrica. *//* www .jav a 2 s.c om*/ public void solicitarClave() { CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpGet httpGet = new HttpGet(Configuration.getInstance().getServerUrl() + "/secretKey?opcion=public"); CloseableHttpResponse response1 = httpclient.execute(httpGet, SessionContext.getInstance().getContext()); try { HttpEntity entity1 = response1.getEntity(); File f = new File("./server1024.publica"); if (f.exists()) { f.delete(); } IOUtils.copy(entity1.getContent(), new FileOutputStream(f)); } finally { response1.close(); } httpGet = new HttpGet(Configuration.getInstance().getServerUrl() + "/secretKey?opcion=secret"); response1 = httpclient.execute(httpGet, SessionContext.getInstance().getContext()); try { HttpEntity entity1 = response1.getEntity(); String respuesta = EntityUtils.toString(entity1); byte[] clave = Base64.decodeBase64(respuesta); //descifro byte[] bufferPub = new byte[5000]; File f = new File("server1024.publica"); System.out.println(f.getAbsolutePath()); FileInputStream in = new FileInputStream(f); int chars = in.read(bufferPub, 0, 5000); in.close(); byte[] bufferPub2 = new byte[chars]; System.arraycopy(bufferPub, 0, bufferPub2, 0, chars); Security.addProvider(new BouncyCastleProvider()); // Cargar el provider BC Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); Cipher cifrador = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); KeyFactory keyFactoryRSA = KeyFactory.getInstance("RSA", "BC"); // Hace uso del provider BC // 4.2 Recuperar clave publica desde datos codificados en formato X509 X509EncodedKeySpec clavePublicaSpec = new X509EncodedKeySpec(bufferPub2); PublicKey clavePublica2 = keyFactoryRSA.generatePublic(clavePublicaSpec); cifrador.init(Cipher.DECRYPT_MODE, clavePublica2); // Descrifra con la clave privada byte[] claveAES = cifrador.doFinal(clave); SecretKey originalKey = new SecretKeySpec(claveAES, 0, claveAES.length, "AES"); SessionContext.getInstance().setSecretKey(originalKey); } finally { response1.close(); } } catch (IOException ex) { Logger.getLogger(ControlEmpleados.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(ControlEmpleados.class.getName()).log(Level.SEVERE, null, ex); } finally { try { httpclient.close(); } catch (IOException ex) { Logger.getLogger(ControlEmpleados.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:controller.CCInstance.java
License:Open Source License
public CCInstance() { Security.addProvider(new BouncyCastleProvider()); }