JavaTM 2 Platform
Standard Ed. 6

javax.xml.crypto.dsig.keyinfo
类 KeyInfoFactory

java.lang.Object
  继承者 javax.xml.crypto.dsig.keyinfo.KeyInfoFactory

public abstract class KeyInfoFactory
extends Object

用于从头创建 KeyInfo 对象或从相应的 XML 表示形式解组 KeyInfo 对象的工厂。

每个 KeyInfoFactory 实例都支持一个特定的 XML 机制类型。要创建 KeyInfoFactory,则需要调用一个静态 getInstance 方法,并传入所需的 XML 机制类型,例如:

KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");

此工厂生成的对象将基于 DOM 并遵守 DOM 互操作性要求,正如 API 概述的 DOM Mechanism Requirements 部分所定义的。有关标准机制类型列表,请参阅 API 概述的 Service Providers 部分。

使用 Provider 机制来注册和加载 KeyInfoFactory 实现。例如,支持 DOM 机制的服务提供者将在 Provider 子类中指定,如下所示:

   put("KeyInfoFactory.DOM", "org.example.DOMKeyInfoFactory");
 

同时,由此工厂创建的 XMLStructure 可能包含特定于 KeyInfo 的状态,并且该状态是不可重用的。

实现至少必须支持默认的机制类型:DOM。

注意,调用者必须使用相同的 KeyInfoFactory 实例来创建特定 KeyInfo 对象的 XMLStructure。如果同时使用来自不同提供者或不同机制类型的 XMLStructure,则行为是不明确的。

并发访问

可保证此类的静态方法是线程安全的。多个线程可以并发调用此类中所定义的静态方法,而不会产生不良效果。

但是,对于此类所定义的非静态方法并非如此。除非具体的提供者另行指定,否则需要并发访问单个 KeyInfoFactory 实例的多个线程应该在它们之间实现同步并提供所需的锁定。对于每个线程都操作一个不同 KeyInfoFactory 实例的多个线程而言,无需实现同步。

从以下版本开始:
1.6

构造方法摘要
protected KeyInfoFactory()
          默认的构造方法,由子类调用。
 
方法摘要
static KeyInfoFactory getInstance()
          返回支持默认 XML 处理机制和表示形式类型(“DOM”) 的 KeyInfoFactory
static KeyInfoFactory getInstance(String mechanismType)
          返回 KeyInfoFactory,它支持指定的 XML 处理机制和表示形式类型(比如:“DOM”)。
static KeyInfoFactory getInstance(String mechanismType, Provider provider)
          返回支持所需的 XML 处理机制和表示形式类型(比如:“DOM”)的 KeyInfoFactory,由指定提供者提供。
static KeyInfoFactory getInstance(String mechanismType, String provider)
          返回支持所需的 XML 处理机制和表示形式类型(比如:“DOM”)的 KeyInfoFactory,由指定提供者提供。
 String getMechanismType()
          返回此 KeyInfoFactory 支持的 XML 处理机制类型和表示形式类型(比如:“DOM”)。
 Provider getProvider()
          返回此 KeyInfoFactory 的提供者。
abstract  URIDereferencer getURIDereferencer()
          返回对 URIDereferencer 的引用,默认情况下用于取消引用 RetrievalMethod 对象中的 URI。
abstract  boolean isFeatureSupported(String feature)
          指示是否支持指定的功能。
abstract  KeyInfo newKeyInfo(List content)
          创建包含指定的密钥信息类型列表的 KeyInfo
abstract  KeyInfo newKeyInfo(List content, String id)
          创建包含指定的密钥信息类型列表和可选 id 的 KeyInfo
abstract  KeyName newKeyName(String name)
          根据指定的名称创建 KeyName
abstract  KeyValue newKeyValue(PublicKey key)
          根据指定的公钥创建 KeyValue
abstract  PGPData newPGPData(byte[] keyId)
          根据指定的 PGP 公钥标识符创建 PGPData
abstract  PGPData newPGPData(byte[] keyId, byte[] keyPacket, List other)
          根据指定的 PGP 公钥标识符、可选的密钥材料包和外部元素的列表,创建 PGPData
abstract  PGPData newPGPData(byte[] keyPacket, List other)
          根据指定的 PGP 密钥材料包和可选的外部元素列表创建 PGPData
abstract  RetrievalMethod newRetrievalMethod(String uri)
          根据指定的 URI 创建 RetrievalMethod
abstract  RetrievalMethod newRetrievalMethod(String uri, String type, List transforms)
          根据指定的参数创建 RetrievalMethod
abstract  X509Data newX509Data(List content)
          创建包含指定的 X.509 内容列表的 X509Data
abstract  X509IssuerSerial newX509IssuerSerial(String issuerName, BigInteger serialNumber)
          根据指定的 X.500 发布方标识名和序列号创建 X509IssuerSerial
abstract  KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure)
          根据特定于机制的 XMLStructure(比如:DOMStructure)实例解组新的 KeyInfo 实例。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

KeyInfoFactory

protected KeyInfoFactory()
默认的构造方法,由子类调用。

方法详细信息

getInstance

public static KeyInfoFactory getInstance(String mechanismType)
返回 KeyInfoFactory,它支持指定的 XML 处理机制和表示形式类型(比如:“DOM”)。

此方法使用标准的 JCA 提供者查找机制来查找并实例化所需机制类型的 KeyInfoFactory 实现。它将从首选的 Provider 开始,遍历已注册的安全 Provider 的列表。返回取自第一个支持指定机制的 Provider 中的新 KeyInfoFactory 对象。

注意,已注册提供者的列表可以通过 Security.getProviders() 方法获得。

参数:
mechanismType - XML 处理机制和表示形式的类型。有关标准机制类型列表,请参阅 API 概述的 Service Providers 部分。
返回:
新的 KeyInfoFactory
抛出:
NullPointerException - 如果 mechanismTypenull
NoSuchMechanismException - 如果没有任何 Provider 支持指定机制的 KeyInfoFactory 实现
另请参见:
Provider

getInstance

public static KeyInfoFactory getInstance(String mechanismType,
                                         Provider provider)
返回支持所需的 XML 处理机制和表示形式类型(比如:“DOM”)的 KeyInfoFactory,由指定提供者提供。注意,指定的 Provider 对象不必已经在提供者列表中注册。

参数:
mechanismType - XML 处理机制和表示形式的类型。有关标准机制类型列表,请参阅 API 概述的 Service Providers 部分。
provider - Provider 对象
返回:
新的 KeyInfoFactory
抛出:
NullPointerException - 如果 mechanismTypeprovidernull
NoSuchMechanismException - 如果不能从指定的 Provider 对象使用指定机制的 KeyInfoFactory 实现
另请参见:
Provider

getInstance

public static KeyInfoFactory getInstance(String mechanismType,
                                         String provider)
                                  throws NoSuchProviderException
返回支持所需的 XML 处理机制和表示形式类型(比如:“DOM”)的 KeyInfoFactory,由指定提供者提供。指定的提供者必须已在安全提供者列表中注册。

注意,已注册提供者的列表可以通过 Security.getProviders() 方法获得。

参数:
mechanismType - XML 处理机制和表示形式的类型。有关标准机制类型列表,请参阅 API 概述的 Service Providers 部分。
provider - 提供者的字符串名称
返回:
新的 KeyInfoFactory
抛出:
NoSuchProviderException - 如果指定的提供者没有在安全提供者列表中注册
NullPointerException - 如果 mechanismTypeprovidernull
NoSuchMechanismException - 如果从指定的提供者不能使用指定机制的 KeyInfoFactory 实现
另请参见:
Provider

getInstance

public static KeyInfoFactory getInstance()
返回支持默认 XML 处理机制和表示形式类型(“DOM”) 的 KeyInfoFactory

此方法使用标准的 JCA 提供者查找机制来查找并实例化默认机制类型的 KeyInfoFactory 实现。它将从首选的 Provider 开始,遍历已注册的安全 Provider 的列表。返回取自第一个支持 DOM 机制的 Provider 中的新 KeyInfoFactory 对象。

注意,已注册提供者的列表可以通过 Security.getProviders() 方法获得。

返回:
新的 KeyInfoFactory
抛出:
NoSuchMechanismException - 如果没有任何 Provider 支持 DOM 机制的 KeyInfoFactory 实现
另请参见:
Provider

getMechanismType

public final String getMechanismType()
返回此 KeyInfoFactory 支持的 XML 处理机制类型和表示形式类型(比如:“DOM”)。

返回:
KeyInfoFactory 支持的 XML 处理机制类型

getProvider

public final Provider getProvider()
返回此 KeyInfoFactory 的提供者。

返回:
KeyInfoFactory 的提供者

newKeyInfo

public abstract KeyInfo newKeyInfo(List content)
创建包含指定的密钥信息类型列表的 KeyInfo

参数:
content - 一个列表,由一个或多个表示密钥信息类型的 XMLStructure 组成。需要复制该列表,以防止随后被修改。
返回:
KeyInfo
抛出:
NullPointerException - 如果 contentnull
IllegalArgumentException - 如果 content 为空
ClassCastException - 如果 content 包含任何不是类型 XMLStructure 的条目

newKeyInfo

public abstract KeyInfo newKeyInfo(List content,
                                   String id)
创建包含指定的密钥信息类型列表和可选 id 的 KeyInfoid 参数表示 XML ID 属性值,对于从其他 XML 结构引用 KeyInfo 很有用。

参数:
content - 一个列表,由一个或多个表示密钥信息类型的 XMLStructure 组成。需要复制该列表,以防止随后被修改。
id - XML ID 的值(可以为 null
返回:
KeyInfo
抛出:
NullPointerException - 如果 contentnull
IllegalArgumentException - 如果 content 为空
ClassCastException - 如果 content 包含任何不是类型 XMLStructure 的条目

newKeyName

public abstract KeyName newKeyName(String name)
根据指定的名称创建 KeyName

参数:
name - 标识密钥的名称
返回:
KeyName
抛出:
NullPointerException - 如果 namenull

newKeyValue

public abstract KeyValue newKeyValue(PublicKey key)
                              throws KeyException
根据指定的公钥创建 KeyValue

参数:
key - 公钥
返回:
KeyValue
抛出:
KeyException - 如果 key 的算法不可识别或不受 KeyInfoFactory 的支持
NullPointerException - 如果 keynull

newPGPData

public abstract PGPData newPGPData(byte[] keyId)
根据指定的 PGP 公钥标识符创建 PGPData

参数:
keyId - RFC 2440 第 11.2 节定义的 PGP 公钥标识符。复制该数组,以防止随后被修改。
返回:
PGPData
抛出:
NullPointerException - 如果 keyIdnull
IllegalArgumentException - 如果密钥 id 的格式不正确

newPGPData

public abstract PGPData newPGPData(byte[] keyId,
                                   byte[] keyPacket,
                                   List other)
根据指定的 PGP 公钥标识符、可选的密钥材料包和外部元素的列表,创建 PGPData

参数:
keyId - RFC 2440 第 11.2 节定义的 PGP 公钥标识符。复制该数组,以防止随后被修改。
keyPacket - RFC 2440 第 5.5 节定义的 PGP 密钥材料包。复制该数组,以防止随后被修改。可以为 null
other - 一个列表,由表示外部名称空间中的元素的 XMLStructure 组成。需要复制该列表,以防止随后被修改。可以为 null 或空。
返回:
PGPData
抛出:
NullPointerException - 如果 keyIdnull
IllegalArgumentException - 如果 keyIdkeyPacket 的格式不正确。对于 keyPacket,将检查包头的格式,并验证标记,确定它属于哪种类型的密钥材料。包正文的内容和格式无需检查。
ClassCastException - 如果 other 包含任何不是类型 XMLStructure 的条目

newPGPData

public abstract PGPData newPGPData(byte[] keyPacket,
                                   List other)
根据指定的 PGP 密钥材料包和可选的外部元素列表创建 PGPData

参数:
keyPacket - RFC 2440 第 5.5 节定义的 PGP 密钥材料包。复制该数组,以防止随后被修改。
other - 一个列表,由表示外部名称空间中的元素的 XMLStructure 组成。需要复制该列表,以防止随后被修改。可以为 null 或空。
返回:
PGPData
抛出:
NullPointerException - 如果 keyPacketnull
IllegalArgumentException - 如果 keyPacket 的格式不正确。对于 keyPacket,将检查包头的格式,并验证标记,确定它属于哪种类型的密钥材料。包正文的内容和格式无需检查。
ClassCastException - 如果 other 包含任何不是类型 XMLStructure 的条目

newRetrievalMethod

public abstract RetrievalMethod newRetrievalMethod(String uri)
根据指定的 URI 创建 RetrievalMethod

参数:
uri - 标识将要检索的 KeyInfo 信息的 URI
返回:
RetrievalMethod
抛出:
NullPointerException - 如果 urinull
IllegalArgumentException - 如果 uri 与 RFC 2396 不兼容

newRetrievalMethod

public abstract RetrievalMethod newRetrievalMethod(String uri,
                                                   String type,
                                                   List transforms)
根据指定的参数创建 RetrievalMethod

参数:
uri - 标识将要检索的 KeyInfo 信息的 URI
type - 标识将要检索的 KeyInfo 信息的类型的 URI (可以为 null
transforms - Transform 的列表。需要复制该列表,以防止随后被修改。可以为 null 或空。
返回:
RetrievalMethod
抛出:
NullPointerException - 如果 urinull
IllegalArgumentException - 如果 uri 与 RFC 2396 不兼容
ClassCastException - 如果 transforms 包含不是类型 Transform 的任何条目

newX509Data

public abstract X509Data newX509Data(List content)
创建包含指定的 X.509 内容列表的 X509Data

参数:
content - 一个列表,由一个或多个 X.509 内容类型组成。有效的类型有 String(主体名称)、byte[](主体的密钥 id)、X509CertificateX509CRLXMLStructure(来自外部名称空间的 X509IssuerSerial 对象或元素)。主体名称是 RFC 2253 String 格式的标识名。这些实现必须支持 RFC 2253(CN、L、ST、O、OU、C、STREET、DC 和 UID)中定义的属性类型关键字。这些实现可能还支持其他关键字。需要复制该列表,以防止随后被修改。
返回:
X509Data
抛出:
NullPointerException - 如果 contentnull
IllegalArgumentException - 如果 content 为空,或者主体与 RFC 2253 不兼容或无法识别其中一个属性类型关键字。
ClassCastException - 如果 content 包含不是上述任何有效类型的任何条目

newX509IssuerSerial

public abstract X509IssuerSerial newX509IssuerSerial(String issuerName,
                                                     BigInteger serialNumber)
根据指定的 X.500 发布方标识名和序列号创建 X509IssuerSerial

参数:
issuerName - RFC 2253 String 格式的发布方标识名。这些实现必须支持 RFC 2253(CN、L、ST、O、OU、C、STREET、DC 和 UID)中定义的属性类型关键字。这些实现可能还支持其他关键字。
serialNumber - 序列号
返回:
X509IssuerSerial
抛出:
NullPointerException - 如果 issuerNameserialNumbernull
IllegalArgumentException - 如果发布方名称与 RFC 2253 不兼容,或者无法识别其中一个属性类型关键字。

isFeatureSupported

public abstract boolean isFeatureSupported(String feature)
指示是否支持指定的功能。

参数:
feature - 功能名称(以抽象 URI 形式)
返回:
如果支持指定功能,则返回 true,否则返回 false
抛出:
NullPointerException - 如果 featurenull

getURIDereferencer

public abstract URIDereferencer getURIDereferencer()
返回对 URIDereferencer 的引用,默认情况下用于取消引用 RetrievalMethod 对象中的 URI。

返回:
对默认 URIDereferencer 的引用

unmarshalKeyInfo

public abstract KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure)
                                  throws MarshalException
根据特定于机制的 XMLStructure(比如:DOMStructure)实例解组新的 KeyInfo 实例。

参数:
xmlStructure - 从中解组 keyinfo 的特定于机制的 XML 结构
返回:
KeyInfo
抛出:
NullPointerException - 如果 xmlStructurenull
ClassCastException - 如果 xmlStructure 的类型不适合此工厂
MarshalException - 如果解组过程中发生不可恢复的异常

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策