JavaTM Platform
Standard Ed. 6

javax.xml.crypto.dsig
接口 XMLSignature

所有超级接口:
XMLStructure

public interface XMLSignature
     
extends XMLStructure

W3C Recommendation for XML-Signature Syntax and Processing 中定义的 XML Signature 元素的表示形式。此类包含一些方法使用 W3C 规范定义的行为对 XML 签名进行签名或验证。XML Schema Definition 的定义如下:


<element name="Signature" type="ds:SignatureType"/>
<complexType name="SignatureType">
<sequence> 
<element ref="ds:SignedInfo"/> 
<element ref="ds:SignatureValue"/> 
<element ref="ds:KeyInfo" minOccurs="0"/> 
<element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/> 
</sequence>  
<attribute name="Id" type="ID" use="optional"/>
</complexType>
 

通过调用 XMLSignatureFactory 类的一个 newXMLSignature 方法,可以创建 XMLSignature 实例。

如果随后修改了包含 XMLSignature 的底层文档的内容,则行为是不确定的。

注意,为避免与现有 java.security.Signature 类发生命名冲突,此类被命名为 XMLSignature,而不是 Signature

从以下版本开始:
1.6
另请参见:
XMLSignatureFactory.newXMLSignature(SignedInfo, KeyInfo), XMLSignatureFactory.newXMLSignature(SignedInfo, KeyInfo, List, String, String)

嵌套类摘要
static interface XMLSignature.SignatureValue
          W3C Recommendation for XML-Signature Syntax and Processing 中定义的 XML SignatureValue 元素的表示形式。
 
字段摘要
static String XMLNS
          W3C Recommendation for XML-Signature Syntax and Processing 的 XML 名称空间 URI。
 
方法摘要
 String getId()
          返回此 XMLSignature 的可选 Id。
 KeyInfo getKeyInfo()
          返回此 XMLSignature 的密钥信息。
 KeySelectorResult getKeySelectorResult()
          在对此 XMLSignature 进行签名或验证后,返回密钥选择器 KeySelector(如果已指定)的结果。
 List getObjects()
          返回一个可修改的列表,由包含在此 XMLSignature 中的 XMLObject 组成。
 XMLSignature.SignatureValue getSignatureValue()
          返回此 XMLSignature 的签名值。
 SignedInfo getSignedInfo()
          返回此 XMLSignature 的签名信息。
 void sign(XMLSignContext signContext)
          为此 XMLSignature 签名。
 boolean validate(XMLValidateContext validateContext)
          根据核心验证处理规则来验证签名。
 
从接口 javax.xml.crypto.XMLStructure 继承的方法
isFeatureSupported
 

字段详细信息

XMLNS

static final String XMLNS
W3C Recommendation for XML-Signature Syntax and Processing 的 XML 名称空间 URI。

另请参见:
常量字段值
方法详细信息

validate

boolean validate(XMLValidateContext validateContext)
                 throws XMLSignatureException
根据 核心验证处理规则来验证签名。此方法使用现有状态验证签名,它并没有使用在上下文中指定的位置信息来解组和重新初始化 XMLSignature 的内容。

此方法只在第一次调用时验证签名。在后续调用时,它将返回一个缓存的结果。

参数:
validateContext - 验证的上下文
返回:
如果签名传递了核心验证,则返回 true,否则返回 false
抛出:
ClassCastException - 如果 validateContext 类型与此 XMLSignature 不兼容
NullPointerException - 如果 validateContextnull
XMLSignatureException - 如果验证期间出现不可预料的错误,从而阻止完成验证操作

getKeyInfo

KeyInfo getKeyInfo()
返回此 XMLSignature 的密钥信息。

返回:
密钥信息(如果未指定该信息,则返回 null

getSignedInfo

SignedInfo getSignedInfo()
返回此 XMLSignature 的签名信息。

返回:
签名信息(永远不能为 null

getObjects

List getObjects()
返回一个 可修改的列表,由包含在此 XMLSignature 中的 XMLObject 组成。

返回:
一个不可修改的 XMLObject 列表(可以为空,但不能为 null

getId

String getId()
返回此 XMLSignature 的可选 Id。

返回:
Id(如果未指定此 Id,则可能返回 null

getSignatureValue

XMLSignature.SignatureValue getSignatureValue()
返回此 XMLSignature 的签名值。

返回:
签名值

sign

void sign(XMLSignContext signContext)
          throws MarshalException,
                 XMLSignatureException
为此 XMLSignature 签名。

如果此方法抛出异常,则此 XMLSignaturesignContext 参数将保持其调用前的状态。

参数:
signContext - 签名的上下文
抛出:
ClassCastException - 如果 signContext 类型与此 XMLSignature 不兼容
NullPointerException - 如果 signContextnull
MarshalException - 如果编组时出现异常
XMLSignatureException - 如果生成签名时出现不可预料的异常

getKeySelectorResult

KeySelectorResult getKeySelectorResult()
在对此 XMLSignature 进行签名或验证后,返回密钥选择器 KeySelector(如果已指定)的结果。

返回:
密钥选择器的结果;如果尚未指定密钥选择器,或尚未对此 XMLSignature 进行签名或验证,则返回 null

JavaTM Platform
Standard Ed. 6

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

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