List of usage examples for java.security Security getProviders
public static Provider[] getProviders(Map<String, String> filter)
From source file:Main.java
/** * Verification: is algorithm supported or not * * @param algorithm/* w w w .j ava 2 s .c o m*/ * @param service * @return */ public static Provider isSupport(String algorithm, String service) { try { Provider[] provs = Security.getProviders(service.concat(".").concat(algorithm)); if (provs == null) { return null; } return (provs.length == 0 ? null : provs[0]); } catch (Exception e) { return null; } }
From source file:org.apache.fop.pdf.PDFEncryptionManager.java
/** * Checks whether the necessary algorithms are available. * @return boolean True if all necessary algorithms are present *///from w w w . ja v a 2 s . c o m public static boolean checkAvailableAlgorithms() { if (!isJCEAvailable()) { return false; } else { Provider[] providers; providers = Security.getProviders("Cipher.RC4"); if (providers == null) { LOG.warn("Cipher provider for RC4 not available."); return false; } providers = Security.getProviders("MessageDigest.MD5"); if (providers == null) { LOG.warn("MessageDigest provider for MD5 not available."); return false; } return true; } }
From source file:org.cesecore.certificates.util.AlgorithmTools.java
/** Check if the curve name is known by the first found PKCS#11 provider or default (if none was found)*/ public static boolean isNamedECKnownInDefaultProvider(String ecNamedCurveBc) { final Provider[] providers = Security.getProviders("KeyPairGenerator.EC"); String providerName = providers[0].getName(); try {/*from w ww . java 2s . c o m*/ for (Provider ecProvider : providers) { //This will list something like: SunPKCS11-NSS, BC, SunPKCS11-<library>-slot<slotnumber> if (log.isDebugEnabled()) { log.debug("Found EC capable provider named: " + ecProvider.getName()); } if (ecProvider.getName().startsWith("SunPKCS11-") && !ecProvider.getName().startsWith("SunPKCS11-NSS")) { providerName = ecProvider.getName(); break; } } final KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", providerName); kpg.initialize(new ECGenParameterSpec(ecNamedCurveBc)); return true; } catch (InvalidAlgorithmParameterException e) { if (log.isDebugEnabled()) { log.debug(ecNamedCurveBc + " is not available in provider " + providerName); } } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "EC capable provider " + providerName + " could no longer handle elliptic curve algorithm..", e); } catch (NoSuchProviderException e) { throw new RuntimeException("EC capable provider " + providerName + " disappeard unexpectedly.", e); } return false; }
From source file:org.hyperic.util.security.DbKeyStore.java
/** * if {@link org.hyperic.hq.context.Bootstrap} exists it will return a DbKeyStore, or else it * returns the regular/* w ww. ja v a 2 s . co m*/ * {@link KeyStore} */ public static KeyStore getInstance(String type, AtomicBoolean isDb) throws KeyStoreException { DbKeystoreManager dbKeystoreManager = null; try { // scottmf: Not happy about this, when the agent is springified we can remove this. Class<?> bootstrapClass = Class.forName("org.hyperic.hq.context.Bootstrap"); Method method = bootstrapClass.getMethod("getBean", String.class); dbKeystoreManager = (DbKeystoreManager) method.invoke(null, "dbKeystoreManager"); } catch (Exception e) { log.debug("could not instantiate DbKeystoreManager class: " + e, e); } if (dbKeystoreManager == null) { isDb.set(false); return KeyStore.getInstance(type); } try { final DbKeyStoreSpi dbKeyStoreSpi = new DbKeyStoreSpi(dbKeystoreManager); final Provider[] providers = Security.getProviders("KeyStore." + type); isDb.set(true); return new DbKeyStore(dbKeyStoreSpi, providers[0], type); } catch (Exception e) { throw new RuntimeException(e); } }