/** * Returns a KeyPairGenerator object that generates public/private key pairs for the specified * algorithm. * * <p>This method traverses the list of registered security Providers, starting with the most * preferred Provider. A new KeyPairGenerator object encapsulating the KeyPairGeneratorSpi * implementation from the first Provider that supports the specified algorithm is returned. * * <p>Note that the list of registered providers may be retrieved via the {@link * Security#getProviders() Security.getProviders()} method. * * @param algorithm the standard string name of the algorithm. See Appendix A in the <a href= * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA"> Java Cryptography * Architecture API Specification & Reference </a> for information about standard * algorithm names. * @return the new KeyPairGenerator object. * @exception NoSuchAlgorithmException if no Provider supports a KeyPairGeneratorSpi * implementation for the specified algorithm. * @see Provider */ public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { List<Service> list = GetInstance.getServices("KeyPairGenerator", algorithm); Iterator<Service> t = list.iterator(); if (t.hasNext() == false) { throw new NoSuchAlgorithmException(algorithm + " KeyPairGenerator not available"); } // find a working Spi or KeyPairGenerator subclass NoSuchAlgorithmException failure = null; do { Service s = t.next(); try { Instance instance = GetInstance.getInstance(s, KeyPairGeneratorSpi.class); if (instance.impl instanceof KeyPairGenerator) { return getInstance(instance, algorithm); } else { return new Delegate(instance, t, algorithm); } } catch (NoSuchAlgorithmException e) { if (failure == null) { failure = e; } } } while (t.hasNext()); throw failure; }
/* * Returns an array of objects: the first object in the array is * an instance of an implementation of the requested algorithm * and type, and the second object in the array identifies the provider * of that implementation. * The <code>provider</code> argument can be null, in which case all * configured providers will be searched in order of preference. */ static Object[] getImpl(String algorithm, String type, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { if (provider == null) { return GetInstance.getInstance(type, getSpiClass(type), algorithm).toArray(); } else { return GetInstance.getInstance(type, getSpiClass(type), algorithm, provider).toArray(); } }
static Instance getInstance(String type, Class<?> clazz, String algorithm, Provider provider) throws NoSuchAlgorithmException { Service s = GetInstance.getService(type, algorithm, provider); Exception ve = JceSecurity.getVerificationResult(provider); if (ve != null) { String msg = "JCE cannot authenticate the provider " + provider.getName(); throw new SecurityException(msg, ve); } return GetInstance.getInstance(s, clazz); }
static Instance getInstance(String type, Class<?> clazz, String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { Service s = GetInstance.getService(type, algorithm, provider); Exception ve = getVerificationResult(s.getProvider()); if (ve != null) { String msg = "JCE cannot authenticate the provider " + provider; throw (NoSuchProviderException) new NoSuchProviderException(msg).initCause(ve); } return GetInstance.getInstance(s, clazz); }
/** * Returns a {@code CertPathValidator} object that implements the specified algorithm. * * <p>A new CertPathValidator object encapsulating the CertPathValidatorSpi implementation from * the specified Provider object is returned. Note that the specified Provider object does not * have to be registered in the provider list. * * @param algorithm the name of the requested {@code CertPathValidator} algorithm. See the * CertPathValidator section in the <a href= * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator"> Java * Cryptography Architecture Standard Algorithm Name Documentation</a> for information about * standard algorithm names. * @param provider the provider. * @return a {@code CertPathValidator} object that implements the specified algorithm. * @exception NoSuchAlgorithmException if a CertPathValidatorSpi implementation for the specified * algorithm is not available from the specified Provider object. * @exception IllegalArgumentException if the {@code provider} is null. * @see java.security.Provider */ public static CertPathValidator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { Instance instance = GetInstance.getInstance( "CertPathValidator", CertPathValidatorSpi.class, algorithm, provider); return new CertPathValidator( (CertPathValidatorSpi) instance.impl, instance.provider, algorithm); }
/** * Returns a <code>KeyManagerFactory</code> object that acts as a factory for key managers. * * <p>This method traverses the list of registered security Providers, starting with the most * preferred Provider. A new KeyManagerFactory object encapsulating the KeyManagerFactorySpi * implementation from the first Provider that supports the specified algorithm is returned. * * <p>Note that the list of registered providers may be retrieved via the {@link * Security#getProviders() Security.getProviders()} method. * * @implNote The JDK Reference Implementation additionally uses the {@code * jdk.security.provider.preferred} {@link Security#getProperty(String) Security} property to * determine the preferred provider order for the specified algorithm. This may be different * than the order of providers returned by {@link Security#getProviders() * Security.getProviders()}. * @param algorithm the standard name of the requested algorithm. See the <a href= * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html"> Java Secure Socket * Extension Reference Guide </a> for information about standard algorithm names. * @return the new {@code KeyManagerFactory} object * @throws NoSuchAlgorithmException if no {@code Provider} supports a {@code KeyManagerFactorySpi} * implementation for the specified algorithm * @throws NullPointerException if {@code algorithm} is {@code null} * @see java.security.Provider */ public static final KeyManagerFactory getInstance(String algorithm) throws NoSuchAlgorithmException { Objects.requireNonNull(algorithm, "null algorithm name"); GetInstance.Instance instance = GetInstance.getInstance("KeyManagerFactory", KeyManagerFactorySpi.class, algorithm); return new KeyManagerFactory( (KeyManagerFactorySpi) instance.impl, instance.provider, algorithm); }
static Instance getInstance(String type, Class<?> clazz, String algorithm) throws NoSuchAlgorithmException { List<Service> services = GetInstance.getServices(type, algorithm); NoSuchAlgorithmException failure = null; for (Service s : services) { if (canUseProvider(s.getProvider()) == false) { // allow only signed providers continue; } try { Instance instance = GetInstance.getInstance(s, clazz); return instance; } catch (NoSuchAlgorithmException e) { failure = e; } } throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available", failure); }
static Object[] getImpl(String algorithm, String type, Provider provider, Object params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { return GetInstance.getInstance(type, getSpiClass(type), algorithm, params, provider).toArray(); }
/* * Returns an array of objects: the first object in the array is * an instance of an implementation of the requested algorithm * and type, and the second object in the array identifies the provider * of that implementation. * The <code>provider</code> argument cannot be null. */ static Object[] getImpl(String algorithm, String type, Provider provider) throws NoSuchAlgorithmException { return GetInstance.getInstance(type, getSpiClass(type), algorithm, provider).toArray(); }
/** * Returns a KeyPairGenerator object that generates public/private key pairs for the specified * algorithm. * * <p>A new KeyPairGenerator object encapsulating the KeyPairGeneratorSpi implementation from the * specified Provider object is returned. Note that the specified Provider object does not have to * be registered in the provider list. * * @param algorithm the standard string name of the algorithm. See Appendix A in the <a href= * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA"> Java Cryptography * Architecture API Specification & Reference </a> for information about standard * algorithm names. * @param provider the provider. * @return the new KeyPairGenerator object. * @exception NoSuchAlgorithmException if a KeyPairGeneratorSpi implementation for the specified * algorithm is not available from the specified Provider object. * @exception IllegalArgumentException if the specified provider is null. * @see Provider * @since 1.4 */ public static KeyPairGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { Instance instance = GetInstance.getInstance("KeyPairGenerator", KeyPairGeneratorSpi.class, algorithm, provider); return getInstance(instance, algorithm); }