public interface KeyValue
W3C Recommendation for XML-Signature Syntax and Processing 中定义的 XML KeyValue 元素的表示形式。KeyValue 对象包含一个在验证签名时很有用的公钥。XML Schema Definition 的定义如下:
<element name="KeyValue" type="ds:KeyValueType"/>
<complexType name="KeyValueType" mixed="true">
<choice>
<element ref="ds:DSAKeyValue"/>
<element ref="ds:RSAKeyValue"/>
<any namespace="##other" processContents="lax"/>
</choice>
</complexType>
<element name="DSAKeyValue" type="ds:DSAKeyValueType"/>
<complexType name="DSAKeyValueType">
<sequence>
<sequence minOccurs="0">
<element name="P" type="ds:CryptoBinary"/>
<element name="Q" type="ds:CryptoBinary"/>
</sequence>
<element name="G" type="ds:CryptoBinary" minOccurs="0"/>
<element name="Y" type="ds:CryptoBinary"/>
<element name="J" type="ds:CryptoBinary" minOccurs="0"/>
<sequence minOccurs="0">
<element name="Seed" type="ds:CryptoBinary"/>
<element name="PgenCounter" type="ds:CryptoBinary"/>
</sequence>
</sequence>
</complexType>
<element name="RSAKeyValue" type="ds:RSAKeyValueType"/>
<complexType name="RSAKeyValueType">
<sequence>
<element name="Modulus" type="ds:CryptoBinary"/>
<element name="Exponent" type="ds:CryptoBinary"/>
</sequence>
</complexType>
通过调用
KeyInfoFactory 类的
newKeyValue 方法,并向其传递表示公钥值的
PublicKey,可以创建
KeyValue 实例。下面是一个示例,该示例根据
KeyStore 中存储的
Certificate 的
DSAPublicKey 创建了一个
KeyValue:
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey();
KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
KeyValue keyValue = factory.newKeyValue(dsaPublicKey);
此类将分别以类型
DSAPublicKey 和
RSAPublicKey 对象的形式返回
DSAKeyValue 和
RSAKeyValue 元素。注意,并非模式中的所有字段都可以作为这些类型的参数进行访问。
KeyInfoFactory.newKeyValue(PublicKey)
| 字段摘要 | |
|---|---|
static String |
DSA_TYPE 标识 DSA KeyValue KeyInfo 类型的 URI:http://www.w3.org/2000/09/xmldsig#DSAKeyValue。 |
static String |
RSA_TYPE 标识 RSA KeyValue KeyInfo 类型的 URI:http://www.w3.org/2000/09/xmldsig#RSAKeyValue。 |
| 方法摘要 | |
|---|---|
PublicKey |
getPublicKey() 返回此 KeyValue 的公钥。 |
| 从接口 javax.xml.crypto.XMLStructure 继承的方法 |
|---|
isFeatureSupported |
| 字段详细信息 |
|---|
static final String DSA_TYPE
RetrievalMethod 类的
type 参数值,以描述远程
DSAKeyValue 结构。
static final String RSA_TYPE
RetrievalMethod 类的
type 参数值,以描述远程
RSAKeyValue 结构。
| 方法详细信息 |
|---|
PublicKey getPublicKey() throws KeyException
KeyValue 的公钥。
KeyValue 的公钥
KeyException - 如果无法将此
KeyValue 转换为
PublicKey