Search in sources :

Example 6 with Instance

use of sun.security.jca.GetInstance.Instance in project jdk8u_jdk by JetBrains.

the class KeyInfoFactory method getInstance.

/**
     * Returns a <code>KeyInfoFactory</code> that supports the
     * requested XML processing mechanism and representation type (ex: "DOM"),
     * as supplied by the specified provider. Note that the specified
     * <code>Provider</code> object does not have to be registered in the
     * provider list.
     *
     * @param mechanismType the type of the XML processing mechanism and
     *    representation. See the <a
     *    href="../../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
     *    Service Providers</a> section of the API overview for a list of
     *    standard mechanism types.
     * @param provider the <code>Provider</code> object
     * @return a new <code>KeyInfoFactory</code>
     * @throws NullPointerException if <code>mechanismType</code> or
     *    <code>provider</code> are <code>null</code>
     * @throws NoSuchMechanismException if a <code>KeyInfoFactory</code>
     *    implementation for the specified mechanism is not available from the
     *    specified <code>Provider</code> object
     * @see Provider
     */
public static KeyInfoFactory getInstance(String mechanismType, Provider provider) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    Instance instance;
    try {
        instance = GetInstance.getInstance("KeyInfoFactory", null, mechanismType, provider);
    } catch (NoSuchAlgorithmException nsae) {
        throw new NoSuchMechanismException(nsae);
    }
    KeyInfoFactory factory = (KeyInfoFactory) instance.impl;
    factory.mechanismType = mechanismType;
    factory.provider = instance.provider;
    return factory;
}
Also used : Instance(sun.security.jca.GetInstance.Instance) NoSuchMechanismException(javax.xml.crypto.NoSuchMechanismException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with Instance

use of sun.security.jca.GetInstance.Instance in project jdk8u_jdk by JetBrains.

the class KeyPairGenerator method getInstance.

/**
     * 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 the KeyPairGenerator section in the <a href=
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
     * Java Cryptography Architecture Standard Algorithm Name Documentation</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;
}
Also used : Instance(sun.security.jca.GetInstance.Instance) Service(java.security.Provider.Service)

Example 8 with Instance

use of sun.security.jca.GetInstance.Instance in project jdk8u_jdk by JetBrains.

the class Signature method getInstance.

/**
     * Returns a Signature object that implements the specified signature
     * algorithm.
     *
     * <p> This method traverses the list of registered security Providers,
     * starting with the most preferred Provider.
     * A new Signature object encapsulating the
     * SignatureSpi 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 name of the algorithm requested.
     * See the Signature section in the <a href=
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
     * for information about standard algorithm names.
     *
     * @return the new Signature object.
     *
     * @exception NoSuchAlgorithmException if no Provider supports a
     *          Signature implementation for the
     *          specified algorithm.
     *
     * @see Provider
     */
public static Signature getInstance(String algorithm) throws NoSuchAlgorithmException {
    List<Service> list;
    if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
        list = GetInstance.getServices(rsaIds);
    } else {
        list = GetInstance.getServices("Signature", algorithm);
    }
    Iterator<Service> t = list.iterator();
    if (t.hasNext() == false) {
        throw new NoSuchAlgorithmException(algorithm + " Signature not available");
    }
    // try services until we find an Spi or a working Signature subclass
    NoSuchAlgorithmException failure;
    do {
        Service s = t.next();
        if (isSpi(s)) {
            return new Delegate(s, t, algorithm);
        } else {
            // must be a subclass of Signature, disable dynamic selection
            try {
                Instance instance = GetInstance.getInstance(s, SignatureSpi.class);
                return getInstance(instance, algorithm);
            } catch (NoSuchAlgorithmException e) {
                failure = e;
            }
        }
    } while (t.hasNext());
    throw failure;
}
Also used : Instance(sun.security.jca.GetInstance.Instance) Service(java.security.Provider.Service)

Example 9 with Instance

use of sun.security.jca.GetInstance.Instance in project jdk8u_jdk by JetBrains.

the class XMLSignatureFactory method getInstance.

/**
     * Returns an <code>XMLSignatureFactory</code> that supports the
     * requested XML processing mechanism and representation type (ex: "DOM"),
     * as supplied by the specified provider. Note that the specified
     * <code>Provider</code> object does not have to be registered in the
     * provider list.
     *
     * @param mechanismType the type of the XML processing mechanism and
     *    representation. See the <a
     *    href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
     *    Service Providers</a> section of the API overview for a list of
     *    standard mechanism types.
     * @param provider the <code>Provider</code> object
     * @return a new <code>XMLSignatureFactory</code>
     * @throws NullPointerException if <code>provider</code> or
     *    <code>mechanismType</code> is <code>null</code>
     * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
     *   implementation for the specified mechanism is not available
     *   from the specified <code>Provider</code> object
     * @see Provider
     */
public static XMLSignatureFactory getInstance(String mechanismType, Provider provider) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    Instance instance;
    try {
        instance = GetInstance.getInstance("XMLSignatureFactory", null, mechanismType, provider);
    } catch (NoSuchAlgorithmException nsae) {
        throw new NoSuchMechanismException(nsae);
    }
    XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
    factory.mechanismType = mechanismType;
    factory.provider = instance.provider;
    return factory;
}
Also used : Instance(sun.security.jca.GetInstance.Instance) NoSuchMechanismException(javax.xml.crypto.NoSuchMechanismException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 10 with Instance

use of sun.security.jca.GetInstance.Instance in project j2objc by google.

the class KeyPairGenerator method getInstance.

/**
     * 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 the KeyPairGenerator section in the <a href=
     * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#KeyPairGenerator">
     * Java Cryptography Architecture Standard Algorithm Name Documentation</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;
}
Also used : Instance(sun.security.jca.GetInstance.Instance) Service(java.security.Provider.Service)

Aggregations

Instance (sun.security.jca.GetInstance.Instance)13 Service (java.security.Provider.Service)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 NoSuchMechanismException (javax.xml.crypto.NoSuchMechanismException)4 NoSuchProviderException (java.security.NoSuchProviderException)1