/** * Returns an array containing all installed providers. The providers are * ordered according their preference order. * * @return an array containing all installed providers. */ public static synchronized Provider[] getProviders() { return Services.getProviders(); }
/** * Returns the {@code Provider} with the specified name. Returns {@code * null} if name is {@code null} or no provider with the specified name is * installed. * * @param name * the name of the requested provider. * @return the provider with the specified name, maybe {@code null}. */ public static synchronized Provider getProvider(String name) { return Services.getProvider(name); }
/** * Returns the default SecureRandom service description. */ public static synchronized Provider.Service getSecureRandomService() { getCacheVersion(); // used for side effect of updating cache if needed return cachedSecureRandomService; }
/** * Finds the appropriate service implementation and returns an * {@code SpiAndProvider} instance containing a reference to SPI * and its {@code Provider} */ public SpiAndProvider getInstance(String algorithm, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("Null algorithm name"); } int newCacheVersion = Services.getCacheVersion(); Provider.Service service; ServiceCacheEntry cacheEntry = this.serviceCache; if (cacheEntry != null && cacheEntry.algorithm.equalsIgnoreCase(algorithm) && newCacheVersion == cacheEntry.cacheVersion) { service = cacheEntry.service; } else { if (Services.isEmpty()) { throw notFound(serviceName, algorithm); } String name = this.serviceName + "." + algorithm.toUpperCase(Locale.US); service = Services.getService(name); if (service == null) { throw notFound(serviceName, algorithm); } this.serviceCache = new ServiceCacheEntry(algorithm, newCacheVersion, service); } return new SpiAndProvider(service.newInstance(param), service.getProvider()); }
private static Signature getSignatureInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { Object spi = ENGINE.getInstance(algorithm, provider, null); if (spi instanceof Signature) { Signature result = (Signature) spi; result.algorithm = algorithm; result.provider = provider; return result; } return new SignatureImpl((SignatureSpi) spi, provider, algorithm); }
/** * Removes the provider at the specified 1-based position. */ public static synchronized void removeProvider(int providerNumber) { Provider p = providers.remove(providerNumber - 1); providersNames.remove(p.getName()); setNeedRefresh(); }
/** * Returns the current cache version. This has the possible side * effect of updating the cache if needed. */ public static synchronized int getCacheVersion() { if (needRefresh) { cacheVersion++; synchronized (services) { services.clear(); } cachedSecureRandomService = null; for (Provider p : providers) { initServiceInfo(p); } needRefresh = false; } return cacheVersion; } }
/** * Returns a new instance of {@code SecureRandom} that utilizes the * specified algorithm. * * @param algorithm * the name of the algorithm to use. * @return a new instance of {@code SecureRandom} that utilizes the * specified algorithm. * @throws NoSuchAlgorithmException * if the specified algorithm is not available. * @throws NullPointerException * if {@code algorithm} is {@code null}. */ public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new SecureRandom((SecureRandomSpi) sap.spi, sap.provider, algorithm); }
/** * * Update sequence numbers of all providers. * */ private static void renumProviders() { Provider[] p = Services.getProviders(); for (int i = 0; i < p.length; i++) { p[i].setProviderNumber(i + 1); } }
private static synchronized void checkCacheVersion() { int newCacheVersion = Services.getCacheVersion(); if (newCacheVersion != cacheVersion) { // // Now search providers for mappings like // Alg.Alias.<service>.<OID-INTS-DOT-SEPARATED>=<alg-name> // or // Alg.Alias.<service>.OID.<OID-INTS-DOT-SEPARATED>=<alg-name> // Provider[] pl = Security.getProviders(); for (Provider element : pl) { selectEntries(element); } cacheVersion = newCacheVersion; } }
/** * Inserts a provider at a specified 1-based position. */ public static synchronized int insertProviderAt(Provider provider, int position) { int size = providers.size(); if ((position < 1) || (position > size)) { position = size + 1; } providers.add(position - 1, provider); providersNames.put(provider.getName(), provider); setNeedRefresh(); return position; }
/** * Returns a new instance of {@code KeyFactory} that utilizes the specified * algorithm. * * @param algorithm * the name of the algorithm. * @return a new instance of {@code KeyFactory} that utilizes the specified * algorithm. * @throws NoSuchAlgorithmException * if no provider provides the requested algorithm. */ public static KeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new KeyFactory((KeyFactorySpi) sap.spi, sap.provider, algorithm); }
/** * Returns a new certification path validator for the specified algorithm. * * @param algorithm * the algorithm name. * @return a certification path validator for the requested algorithm. * @throws NoSuchAlgorithmException * if no installed provider provides the specified algorithm. * @throws NullPointerException * if algorithm is {@code null}. */ public static CertPathValidator getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new CertPathValidator((CertPathValidatorSpi) sap.spi, sap.provider, algorithm); }
/** * Creates a new {@code KeyAgreement} for the specified algorithm. * * @param algorithm * the name of the key agreement algorithm to create. * @return a key agreement for the specified algorithm. * @throws NoSuchAlgorithmException * if no installed provider can provide the requested algorithm. * @throws NullPointerException * if the specified algorithm is {@code null}. */ public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new KeyAgreement((KeyAgreementSpi) sap.spi, sap.provider, algorithm); }
/** * Creates a new {@code SSLContext} instance for the specified protocol. * * @param protocol * the requested protocol to create a context for. * @return the created {@code SSLContext} instance. * @throws NoSuchAlgorithmException * if no installed provider can provide the requested protocol * @throws NullPointerException * if {@code protocol} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) */ public static SSLContext getInstance(String protocol) throws NoSuchAlgorithmException { if (protocol == null) { throw new NullPointerException("protocol == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(protocol, null); return new SSLContext((SSLContextSpi) sap.spi, sap.provider, protocol); }
/** * Creates a new {@code KeyGenerator} instance that provides the specified * key algorithm, * * @param algorithm * the name of the requested key algorithm * @return the new {@code KeyGenerator} instance. * @throws NoSuchAlgorithmException * if the specified algorithm is not available by any provider. * @throws NullPointerException * if {@code algorithm} is {@code null}. */ public static final KeyGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new KeyGenerator((KeyGeneratorSpi) sap.spi, sap.provider, algorithm); }
/** * Creates a new {@code SecretKeyFactory} instance for the specified key * algorithm. * * @param algorithm * the name of the key algorithm. * @return a secret key factory for the specified key algorithm. * @throws NoSuchAlgorithmException * if no installed provider can provide the requested algorithm. * @throws NullPointerException * if the specified algorithm is {@code null}. */ public static final SecretKeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new SecretKeyFactory((SecretKeyFactorySpi) sap.spi, sap.provider, algorithm); }
/** * Creates a new {@code CertPathBuilder} instance with the specified * algorithm. * * @param algorithm * the name of the algorithm. * @return a builder for the requested algorithm. * @throws NullPointerException * if the algorithm is {@code null}. * @throws NoSuchAlgorithmException * if no installed provider can provide the algorithm. */ public static CertPathBuilder getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new CertPathBuilder((CertPathBuilderSpi) sap.spi, sap.provider, algorithm); }
/** * Returns a new {@code ExemptionMechanism} instance that provides the * specified exemption mechanism algorithm. * * @param algorithm * the name of the requested exemption mechanism. * @return the new {@code ExemptionMechanism} instance. * @throws NoSuchAlgorithmException * if the specified algorithm is not available by any provider. * @throws NullPointerException * if the algorithm parameter is {@code null}. */ public static final ExemptionMechanism getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new ExemptionMechanism((ExemptionMechanismSpi) sap.spi, sap.provider, algorithm); }
/** * Creates a new {@code Mac} instance that provides the specified MAC * algorithm. * * @param algorithm * the name of the requested MAC algorithm. * @return the new {@code Mac} instance. * @throws NoSuchAlgorithmException * if the specified algorithm is not available by any provider. * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release). */ public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NullPointerException("algorithm == null"); } Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null); return new Mac((MacSpi) sap.spi, sap.provider, algorithm); }