/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
private static <T> Iterator<T> getFactories(Class<T> type, ClassLoader classLoader, boolean includeGlobal) { Set<T> factories = new LinkedHashSet<>(); final ServiceLoader<T> loader = ServiceLoader.load(type, classLoader); for (T factory : loader) { factories.add(factory); } if (includeGlobal) { Set<String> loadedClasses = new HashSet<>(); final String filter = type.getSimpleName() + "."; Provider[] providers = Security.getProviders(); for (Provider currentProvider : providers) { final ClassLoader cl = currentProvider.getClass().getClassLoader(); currentProvider.keySet().stream().filter(currentKey -> currentKey instanceof String && ((String)currentKey).startsWith(filter) && ((String)currentKey).indexOf(' ') < 0).forEach(currentKey -> { String className=currentProvider.getProperty((String)currentKey); if(className != null && loadedClasses.add(className)) { try { factories.add(Class.forName(className, true, cl).asSubclass(type).newInstance()); } catch(ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException e) { } } }); } } return factories.iterator(); }
/** * Returns value for the specified algorithm with the specified name. * * @param algName * the name of the algorithm. * @param propName * the name of the property. * @return value of the property. * @deprecated Use {@link AlgorithmParameters} and {@link KeyFactory} instead. */ @Deprecated public static String getAlgorithmProperty(String algName, String propName) { if (algName == null || propName == null) { return null; } String prop = "Alg." + propName + "." + algName; Provider[] providers = getProviders(); for (Provider provider : providers) { for (Enumeration e = provider.propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (propertyName.equalsIgnoreCase(prop)) { return provider.getProperty(propertyName); } } } return null; }
((String) currentKey).startsWith(filter) && ((String) currentKey).indexOf(' ') < 0) { String className = currentProvider.getProperty((String) currentKey); if (className != null && loadedClasses.add(className)) { try {
@Test public void listCryptoSettingsAvailable() { logger.log(Level.INFO, "Listing security providers and properties:"); for (Provider provider: Security.getProviders()) { logger.log(Level.INFO, "- Provider '"+provider.getName()+"' "); List<String> propertyNames = new ArrayList<String>(); propertyNames.addAll(provider.stringPropertyNames()); Collections.sort(propertyNames); for (String key : propertyNames) { logger.log(Level.INFO, " "+provider.getName()+" / "+key+" = "+provider.getProperty(key)); } } } }
import java.security.*; for (Provider provider: Security.getProviders()) { System.out.println(provider.getName()); for (String key: provider.stringPropertyNames()) System.out.println("\t" + key + "\t" + provider.getProperty(key)); }
for (Provider provider: Security.getProviders()) { System.out.println(provider.getName()); for (String key: provider.stringPropertyNames()) System.out.println("\t" + key + "\t" + provider.getProperty(key)); }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
public String getProperty(String key) { Provider p = getProvider(); if (p != null) { return p.getProperty(key); } else { return null; } }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
/** * Returns the property with the specified key in the provider properties. * The name is not case-sensitive. */ private String getPropertyIgnoreCase(String key) { String res = getProperty(key); if (res != null) { return res; } for (Enumeration<?> e = propertyNames(); e.hasMoreElements(); ) { String propertyName = (String) e.nextElement(); if (key.equalsIgnoreCase(propertyName)) { return getProperty(propertyName); } } return null; }
private String getAlgorithmClass(String algorithm, String serviceType, Provider provider) { /* * Looking for the property name that matches * "<service type>.<algorithm>". The value of the property is the class * name */ String match = serviceType + "." + algorithm; for (Enumeration<?> names = provider.propertyNames(); names.hasMoreElements();) { String key = (String) names.nextElement(); if (key.equals(match)) { return provider.getProperty(key); } } return null; }
private String[] getAlgorithmAliases(String algorithm, String serviceType, Provider provider) { /* * Looking to match property names with key "Alg.Alias.<service type>." * and value of algorithm. The alias is the text following the '.' in * the property name. Return in alpha order */ String matchAlias = "Alg.Alias." + serviceType + "."; ArrayList<String> aliasList = new ArrayList<String>(); for (Enumeration<?> names = provider.propertyNames(); names.hasMoreElements();) { String key = (String) names.nextElement(); if (provider.getProperty(key).equals(algorithm)) { if (key.startsWith(matchAlias)) { String alias = key.substring(matchAlias.length()); aliasList.add(alias); } } } String[] aliases = aliasList.toArray(new String[aliasList.size()]); Arrays.sort(aliases); return aliases; }
import java.security.Provider; import java.security.Security; import java.util.Arrays; public class ShowCryptoProviders { private static final String EOL = System.getProperty("line.separator"); public static void main(final String[] args) { final Provider[] providers = Security.getProviders(); final Boolean verbose = Arrays.asList(args).contains("-v"); for (final Provider p : providers) { System.out.format("%s %s%s", p.getName(), p.getVersion(), EOL); for (final Object o : p.keySet()) { if (verbose) { System.out.format("\t%s : %s%s", o, p.getProperty((String)o), EOL); } } } } }
public String getSigAlgName() { Provider[] provs = Security.getProviders(); // // search every provider looking for a real algorithm // for (int i = 0; i != provs.length; i++) { String algName = provs[i].getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if ( algName != null ) { return algName; } } return this.getSigAlgOID(); }
public String getSigAlgName() { Provider[] provs = Security.getProviders(); // // search every provider looking for a real algorithm // for (int i = 0; i != provs.length; i++) { String algName = provs[i].getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if ( algName != null ) { return algName; } } return this.getSigAlgOID(); }
/** * return a more "meaningful" representation for the signature algorithm used in * the certficate. */ public String getSigAlgName() { Provider[] provs = Security.getProviders(); // // search every provider looking for a real algorithm // for (int i = 0; i != provs.length; i++) { String algName = provs[i].getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if (algName != null) { return algName; } } return this.getSigAlgOID(); }