sun.security.jca.GetInstance.Instance Java Examples

The following examples show how to use sun.security.jca.GetInstance.Instance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyPairGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static KeyPairGenerator getInstance(Instance instance,
        String algorithm) {
    KeyPairGenerator kpg;
    if (instance.impl instanceof KeyPairGenerator) {
        kpg = (KeyPairGenerator)instance.impl;
    } else {
        KeyPairGeneratorSpi spi = (KeyPairGeneratorSpi)instance.impl;
        kpg = new Delegate(spi, algorithm);
    }
    kpg.provider = instance.provider;

    if (!skipDebug && pdebug != null) {
        pdebug.println("KeyPairGenerator." + algorithm +
            " algorithm from: " + kpg.provider.getName());
    }

    return kpg;
}
 
Example #2
Source File: JceSecurity.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: JceSecurity.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: KeyPairGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static KeyPairGenerator getInstance(Instance instance,
        String algorithm) {
    KeyPairGenerator kpg;
    if (instance.impl instanceof KeyPairGenerator) {
        kpg = (KeyPairGenerator)instance.impl;
    } else {
        KeyPairGeneratorSpi spi = (KeyPairGeneratorSpi)instance.impl;
        kpg = new Delegate(spi, algorithm);
    }
    kpg.provider = instance.provider;

    if (!skipDebug && pdebug != null) {
        pdebug.println("KeyPairGenerator." + algorithm +
            " algorithm from: " + kpg.provider.getName());
    }

    return kpg;
}
 
Example #5
Source File: Signature.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Signature getInstanceRSA(Provider p)
        throws NoSuchAlgorithmException {
    // try Signature first
    Service s = p.getService("Signature", RSA_SIGNATURE);
    if (s != null) {
        Instance instance = GetInstance.getInstance(s, SignatureSpi.class);
        return getInstance(instance, RSA_SIGNATURE);
    }
    // check Cipher
    try {
        Cipher c = Cipher.getInstance(RSA_CIPHER, p);
        return new Delegate(new CipherAdapter(c), RSA_SIGNATURE);
    } catch (GeneralSecurityException e) {
        // throw Signature style exception message to avoid confusion,
        // but append Cipher exception as cause
        throw new NoSuchAlgorithmException("no such algorithm: "
            + RSA_SIGNATURE + " for provider " + p.getName(), e);
    }
}
 
Example #6
Source File: TransformService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism 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 algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #7
Source File: JceSecurity.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: Signature.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private static Signature getInstance(Instance instance, String algorithm) {
    Signature sig;
    if (instance.impl instanceof Signature) {
        sig = (Signature)instance.impl;
        sig.algorithm = algorithm;
    } else {
        SignatureSpi spi = (SignatureSpi)instance.impl;
        sig = new Delegate(spi, algorithm);
    }
    sig.provider = instance.provider;
    return sig;
}
 
Example #9
Source File: JceSecurity.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: TransformService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism 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 algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #11
Source File: Signature.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: TransformService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #13
Source File: KeyPairGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
Delegate(Instance instance, Iterator<Service> serviceIterator,
        String algorithm) {
    super(algorithm);
    spi = (KeyPairGeneratorSpi)instance.impl;
    provider = instance.provider;
    this.serviceIterator = serviceIterator;
    initType = I_NONE;

    if (!skipDebug && pdebug != null) {
        pdebug.println("KeyPairGenerator." + algorithm +
            " algorithm from: " + provider.getName());
    }
}
 
Example #14
Source File: KeyPairGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: TransformService.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #16
Source File: TransformService.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism 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 algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #17
Source File: TransformService.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #18
Source File: Signature.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: Signature.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Signature getInstance(Instance instance, String algorithm) {
    Signature sig;
    if (instance.impl instanceof Signature) {
        sig = (Signature)instance.impl;
        sig.algorithm = algorithm;
    } else {
        SignatureSpi spi = (SignatureSpi)instance.impl;
        sig = new Delegate(spi, algorithm);
    }
    sig.provider = instance.provider;
    return sig;
}
 
Example #20
Source File: TransformService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example #21
Source File: KeyInfoFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. The specified provider must be
 * registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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 string name of the provider
 * @return a new <code>KeyInfoFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @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 provider
 * @see Provider
 */
public static KeyInfoFactory getInstance(String mechanismType,
    String provider) throws NoSuchProviderException {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }

    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;
}
 
Example #22
Source File: XMLSignatureFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. The specified provider must be
 * registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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 string name of the provider
 * @return a new <code>XMLSignatureFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @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 provider
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType,
    String provider) throws NoSuchProviderException {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }

    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;
}
 
Example #23
Source File: KeyInfoFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: XMLSignatureFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: XMLSignatureFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: XMLSignatureFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. The specified provider must be
 * registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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 string name of the provider
 * @return a new <code>XMLSignatureFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @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 provider
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType,
    String provider) throws NoSuchProviderException {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }

    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;
}
 
Example #27
Source File: KeyInfoFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that supports the
 * specified XML processing mechanism and representation type (ex: "DOM").
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>KeyInfoFactory</code> implementation of
 * the desired mechanism type. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>KeyInfoFactory</code> object
 * from the first <code>Provider</code> that supports the specified
 * mechanism is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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.
 * @return a new <code>KeyInfoFactory</code>
 * @throws NullPointerException if <code>mechanismType</code> is
 *    <code>null</code>
 * @throws NoSuchMechanismException if no <code>Provider</code> supports a
 *    <code>KeyInfoFactory</code> implementation for the specified mechanism
 * @see Provider
 */
public static KeyInfoFactory getInstance(String mechanismType) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    }
    Instance instance;
    try {
        instance = GetInstance.getInstance
            ("KeyInfoFactory", null, mechanismType);
    } catch (NoSuchAlgorithmException nsae) {
        throw new NoSuchMechanismException(nsae);
    }
    KeyInfoFactory factory = (KeyInfoFactory) instance.impl;
    factory.mechanismType = mechanismType;
    factory.provider = instance.provider;
    return factory;
}
 
Example #28
Source File: Signature.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a Signature object that implements the specified signature
 * algorithm.
 *
 * <p> A new Signature object encapsulating the
 * SignatureSpi implementation from the specified provider
 * is returned.  The specified provider must be registered
 * in the security provider list.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the 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.
 *
 * @param provider the name of the provider.
 *
 * @return the new Signature object.
 *
 * @exception NoSuchAlgorithmException if a SignatureSpi
 *          implementation for the specified algorithm is not
 *          available from the specified provider.
 *
 * @exception NoSuchProviderException if the specified provider is not
 *          registered in the security provider list.
 *
 * @exception IllegalArgumentException if the provider name is null
 *          or empty.
 *
 * @see Provider
 */
public static Signature getInstance(String algorithm, String provider)
        throws NoSuchAlgorithmException, NoSuchProviderException {
    if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
        // exception compatibility with existing code
        if ((provider == null) || (provider.length() == 0)) {
            throw new IllegalArgumentException("missing provider");
        }
        Provider p = Security.getProvider(provider);
        if (p == null) {
            throw new NoSuchProviderException
                ("no such provider: " + provider);
        }
        return getInstanceRSA(p);
    }
    Instance instance = GetInstance.getInstance
            ("Signature", SignatureSpi.class, algorithm, provider);
    return getInstance(instance, algorithm);
}
 
Example #29
Source File: KeyInfoFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a <code>KeyInfoFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. The specified provider must be
 * registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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 string name of the provider
 * @return a new <code>KeyInfoFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @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 provider
 * @see Provider
 */
public static KeyInfoFactory getInstance(String mechanismType,
    String provider) throws NoSuchProviderException {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }

    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;
}
 
Example #30
Source File: XMLSignatureFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * specified XML processing mechanism and representation type (ex: "DOM").
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate an <code>XMLSignatureFactory</code>
 * implementation of the desired mechanism type. It traverses the list of
 * registered security <code>Provider</code>s, starting with the most
 * preferred <code>Provider</code>.  A new <code>XMLSignatureFactory</code>
 * object from the first <code>Provider</code> that supports the specified
 * mechanism is returned.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @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.
 * @return a new <code>XMLSignatureFactory</code>
 * @throws NullPointerException if <code>mechanismType</code> is
 *    <code>null</code>
 * @throws NoSuchMechanismException if no <code>Provider</code> supports an
 *    <code>XMLSignatureFactory</code> implementation for the specified
 *    mechanism
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    }
    Instance instance;
    try {
        instance = GetInstance.getInstance
            ("XMLSignatureFactory", null, mechanismType);
    } catch (NoSuchAlgorithmException nsae) {
        throw new NoSuchMechanismException(nsae);
    }
    XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
    factory.mechanismType = mechanismType;
    factory.provider = instance.provider;
    return factory;
}