/** * see if we can find an algorithm (or its alias and what it represents) in the property table for * the given provider. * * @return null if no algorithm found, an Implementation if it is. */ static Implementation getImplementation( String baseName, String algorithm, Provider prov, Class[] ctorparamtype, Object[] ctorparam) throws InvalidAlgorithmParameterException { String alias; while ((alias = prov.getProperty("Alg.Alias." + baseName + "." + algorithm)) != null) { algorithm = alias; } String className = prov.getProperty(baseName + "." + algorithm); if (className != null) { try { return new Implementation( Class.forName(className).getConstructor(ctorparamtype).newInstance(ctorparam), prov); } catch (ClassNotFoundException e) { throw new IllegalStateException( "algorithm " + algorithm + " in provider " + prov.getName() + " but no class found!"); } catch (Exception e) { if (e instanceof InvalidAlgorithmParameterException) { throw (InvalidAlgorithmParameterException) e; } throw new IllegalStateException( "algorithm " + algorithm + " in provider " + prov.getName() + " but class inaccessible!"); } } return null; }
/** * Returns the value attached to a provider property. * * <p>Supports aliases, i.e. if there is no property named type.name but one named * Alg.Alias.type.name, the value of Alg.Alias.type.name is assumed to be the <b>name</b> of the * actual property. * * @param provider JCE provider * @param type type (Cipher, Algorithm, ...) * @param name transformation * @return the properties value which usually is the implementing class'es name */ private static String resolveProperty( final Provider provider, final String type, final String name) { if (Provider.getProperty(type + "." + name) != null) return Provider.getProperty(type + "." + name); else if (Provider.getProperty("Alg.Alias." + type + "." + name) != null) return resolveProperty( provider, type, Provider.getProperty("Alg.Alias." + type + "." + name)); else return null; }
/** * return a more "meaningful" representation for the signature algorithm used in the certficate. */ public String getSigAlgName() { Provider prov = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME); if (prov != null) { String algName = prov.getProperty("Alg.Alias.Signature." + this.getSigAlgOID()); if (algName != null) { return algName; } } 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(); }
/** * see if we can find an algorithm (or its alias and what it represents) in the property table for * the given provider. * * @return null if no algorithm found, an Implementation if it is. */ static Implementation getImplementation(String baseName, String algorithm, Provider prov) { if (prov == null) { Provider[] provider = Security.getProviders(); // // search every provider looking for the algorithm we want. // for (int i = 0; i != provider.length; i++) { Implementation imp = getImplementation(baseName, algorithm, provider[i]); if (imp != null) { return imp; } } return null; } String alias; while ((alias = prov.getProperty("Alg.Alias." + baseName + "." + algorithm)) != null) { algorithm = alias; } String className = prov.getProperty(baseName + "." + algorithm); if (className != null) { try { return new Implementation(Class.forName(className).newInstance(), prov); } catch (ClassNotFoundException e) { throw new IllegalStateException( "algorithm " + algorithm + " in provider " + prov.getName() + " but no class found!"); } catch (Exception e) { throw new IllegalStateException( "algorithm " + algorithm + " in provider " + prov.getName() + " but class inaccessible: " + e.toString()); } } return null; }
private static Object findImplEngine(final String baseName, String algorithm) { final Provider bcProvider = securityProvider; String alias; while ((alias = bcProvider.getProperty("Alg.Alias." + baseName + "." + algorithm)) != null) { algorithm = alias; } final String className = bcProvider.getProperty(baseName + "." + algorithm); if (className != null) { try { Class klass; ClassLoader loader = bcProvider.getClass().getClassLoader(); if (loader != null) { klass = loader.loadClass(className); } else { klass = Class.forName(className); } return klass.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalStateException( "algorithm " + algorithm + " in provider " + bcProvider.getName() + " but no class \"" + className + "\" found!"); } catch (Exception e) { throw new IllegalStateException( "algorithm " + algorithm + " in provider " + bcProvider.getName() + " but class \"" + className + "\" inaccessible!"); } } return null; }