⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyinfofactory.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. *//* * $Id: KeyInfoFactory.java,v 1.12 2005/05/10 16:35:35 mullan Exp $ */package javax.xml.crypto.dsig.keyinfo;import java.math.BigInteger;import java.security.KeyException;import java.security.NoSuchAlgorithmException;import java.security.NoSuchProviderException;import java.security.Provider;import java.security.PublicKey;import java.security.Security;import java.security.cert.X509CRL;import java.util.List;import javax.xml.crypto.MarshalException;import javax.xml.crypto.NoSuchMechanismException;import javax.xml.crypto.URIDereferencer;import javax.xml.crypto.XMLStructure;import javax.xml.crypto.dom.DOMStructure;import javax.xml.crypto.dsig.*;import sun.security.jca.*;import sun.security.jca.GetInstance.Instance;/** * A factory for creating {@link KeyInfo} objects from scratch or for * unmarshalling a <code>KeyInfo</code> object from a corresponding XML  * representation. * * <p>Each instance of <code>KeyInfoFactory</code> supports a specific * XML mechanism type. To create a <code>KeyInfoFactory</code>, call one of the * static {@link #getInstance getInstance} methods, passing in the XML  * mechanism type desired, for example: * * <blockquote><code> *   KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM"); * </code></blockquote> * * <p>The objects that this factory produces will be based * on DOM and abide by the DOM interoperability requirements as defined in the * <a href="../../../../../../technotes/guides/security/xmldsig/overview.html#DOM Mechanism Requirements"> * DOM Mechanism Requirements</a> section of the API overview. 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. * * <p><code>KeyInfoFactory</code> implementations are registered and loaded * using the {@link java.security.Provider} mechanism. * For example, a service provider that supports the * DOM mechanism would be specified in the <code>Provider</code> subclass as: * <pre> *     put("KeyInfoFactory.DOM", "org.example.DOMKeyInfoFactory"); * </pre> * * <p>Also, the <code>XMLStructure</code>s that are created by this factory * may contain state specific to the <code>KeyInfo</code> and are not * intended to be reusable. * * <p>An implementation MUST minimally support the default mechanism type: DOM. * * <p>Note that a caller must use the same <code>KeyInfoFactory</code> * instance to create the <code>XMLStructure</code>s of a particular * <code>KeyInfo</code> object. The behavior is undefined if  * <code>XMLStructure</code>s from different providers or different mechanism  * types are used together. * * <p><b>Concurrent Access</b> * <p>The static methods of this class are guaranteed to be thread-safe.  * Multiple threads may concurrently invoke the static methods defined in this  * class with no ill effects. * * <p>However, this is not true for the non-static methods defined by this  * class. Unless otherwise documented by a specific provider, threads that  * need to access a single <code>KeyInfoFactory</code> instance concurrently  * should synchronize amongst themselves and provide the necessary locking.  * Multiple threads each manipulating a different <code>KeyInfoFactory</code>  * instance need not synchronize. * * @author Sean Mullan * @author JSR 105 Expert Group * @since 1.6 */public abstract class KeyInfoFactory {    private String mechanismType;    private Provider provider;    /**     * Default constructor, for invocation by subclasses.     */    protected KeyInfoFactory() {}    /**     * 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;    }    /**     * 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;    }    /**     * 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;    }    /**     * Returns a <code>KeyInfoFactory</code> that supports the     * default XML processing mechanism and representation type ("DOM").     *     * <p>This method uses the standard JCA provider lookup mechanism to      * locate and instantiate a <code>KeyInfoFactory</code> implementation of      * the default 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 DOM mechanism is      * returned.      *      * <p> Note that the list of registered providers may be retrieved via      * the {@link Security#getProviders() Security.getProviders()} method.      *     * @return a new <code>KeyInfoFactory</code>     * @throws NoSuchMechanismException if no <code>Provider</code> supports a      *    <code>KeyInfoFactory</code> implementation for the DOM mechanism     * @see Provider     */    public static KeyInfoFactory getInstance() {        return getInstance("DOM");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -