List of usage examples for java.security Security getProvider
public static Provider getProvider(String name)
From source file:MainClass.java
public static void main(String[] args) { String providerName = "BC"; if (Security.getProvider(providerName) == null) { System.out.println(providerName + " provider not installed"); } else {/*w w w . j av a2 s . c om*/ System.out.println(providerName + " is installed."); } }
From source file:MainClass.java
public static void main(String[] args) { Provider provider = Security.getProvider("BC"); Iterator it = provider.keySet().iterator(); while (it.hasNext()) { String entry = (String) it.next(); if (entry.startsWith("Alg.Alias.")) { entry = entry.substring("Alg.Alias.".length()); }/*from ww w. j a v a 2 s .c o m*/ System.out.println(entry); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Provider p = Security.getProvider("Rot13Provider"); System.out.println("Provider name: " + p.getName()); System.out.println("Provider version: " + p.getVersion()); System.out.println("Provider information: " + p.getInfo()); Cipher cipher = Cipher.getInstance("ROT13", "Rot13Provider"); System.out.println("Cipher: " + cipher.getAlgorithm()); String testString = "This is a test!"; cipher.init(Cipher.ENCRYPT_MODE, (Key) null, new SecureRandom()); byte[] b1 = cipher.doFinal(testString.getBytes()); cipher.init(Cipher.DECRYPT_MODE, (Key) null, new SecureRandom()); byte[] b2 = cipher.doFinal(b1); System.out.println("Decrypted data as a String: " + new String(b2)); }
From source file:VerifyDescriptors.java
public static void main(String[] args) throws Exception { System.out.println("Verifying consensuses..."); if (Security.getProvider("BC") == null) { Security.addProvider(new BouncyCastleProvider()); }//from w ww. j av a2s . c o m verifyServerDescriptors(); verifyConsensuses(); }
From source file:Main.java
protected static boolean initProvider(String providerName, String className) { try {/*w w w. ja va 2 s. co m*/ Provider provider = Security.getProvider(providerName); if (provider == null) { @SuppressWarnings("rawtypes") Class clazz = Class.forName(className); provider = (Provider) clazz.newInstance(); Security.addProvider(provider); } return true; } catch (Throwable ignored) { } return false; }
From source file:Main.java
static Provider getProvider(String provider) throws NoSuchProviderException { Provider prov = Security.getProvider(provider); if (prov == null) { throw new NoSuchProviderException("Provider " + provider + " not found"); }//from w w w . j ava 2s .c o m return prov; }
From source file:com.amazonaws.services.s3.internal.crypto.CryptoRuntime.java
public static boolean isBouncyCastleAvailable() { return Security.getProvider(BOUNCY_CASTLE_PROVIDER) != null; }
From source file:Main.java
public static void setupSunPKCS11Provider(String pkcs11LibPath, final char[] password) { // Prevents installing the provider twice. if (Security.getProvider("SunPKCS11-verinice") != null) return;//from w ww . j a va2 s . c o m // If the user enabled anything PKCS#11 related we need to lead the // PKCS#11 library and add its // provider. String configFile = createPKCS11ConfigFile(pkcs11LibPath); if (configFile != null) { // The availability of this class in an OSGi environment depends on // a system property. If // get errors of this class not being available check that you have // -Dosgi.parentClassloader=ext // in your VM arguments. SunPKCS11 p = new SunPKCS11(configFile); p.setCallbackHandler(new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { ((PasswordCallback) callbacks[0]).setPassword(password); } }); Security.addProvider(p); } }
From source file:com.nkapps.billing.services.ProviderFactoryImpl.java
@Override public Provider getProvider() { if (provider != null) { return provider; }//from www. j a v a 2s.co m provider = Security.getProvider("BC"); if (provider == null) { BouncyCastleProvider bcp = new BouncyCastleProvider(); // configure fake provider Security.addProvider(bcp); provider = bcp; } return provider; }
From source file:com.aqnote.shared.cryptology.util.ProviderUtil.java
public static void addProvider(Provider provider) throws Exception { if (provider == null || Security.getProvider(provider.getName()) != null) return;//w w w . j a va 2 s . co m Security.insertProviderAt(provider, 1); }