APIdia Launch Partner
Top Description Inners Fields Methods
javax.xml.crypto.dsig

public Interface XMLSignature

extends XMLStructure
Known Direct Implementers
org.jcp.xml.dsig.internal.dom.DOMXMLSignature
Imports
javax.xml.crypto.KeySelector, .KeySelectorResult, .MarshalException, .XMLStructure, javax.xml.crypto.dsig.keyinfo.KeyInfo, java.security.Signature, java.util.List

A representation of the XML Signature element as defined in the W3C Recommendation for XML-Signature Syntax and Processing. This class contains methods for signing and validating XML signatures with behavior as defined by the W3C specification. The XML Schema Definition is defined as:

<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>

An XMLSignature instance may be created by invoking one of the newXMLSignature methods of the XMLSignatureFactory class.

If the contents of the underlying document containing the XMLSignature are subsequently modified, the behavior is undefined.

Note that this class is named XMLSignature rather than Signature to avoid naming clashes with the existing java.security.Signature class.

Authors
Joyce L. Leung, Sean Mullan, Erwin van der Koogh, JSR 105 Expert Group
Since
1.6
See Also
XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo), XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo, List, String, String)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
XMLSignature.SignatureValue

A representation of the XML SignatureValue element as defined in the W3C Recommendation for XML-Signature Syntax and Processing.

Field Summary

Modifier and TypeField and Description
public static final String
XMLNS

The XML Namespace URI of the W3C Recommendation for XML-Signature Syntax and Processing.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the Id (may be null if not specified)
getId
()

Returns the optional Id of this XMLSignature.

public KeyInfo

Returns:

the key info (may be null if not specified)
getKeyInfo
()

Returns the key info of this XMLSignature.

public KeySelectorResult

Returns:

the key selector result, or null if a key selector has not been specified or this XMLSignature has not been signed or validated
getKeySelectorResult
()

Returns the result of the KeySelector, if specified, after this XMLSignature has been signed or validated.

public List<XMLObject>

Returns:

an unmodifiable list of XMLObjects (may be empty but never null)
getObjects
()

Returns an unmodifiable list of XMLObjects contained in this XMLSignature.

public XMLSignature.SignatureValue

Returns:

the signature value
getSignatureValue
()

Returns the signature value of this XMLSignature.

public SignedInfo

Returns:

the signed info (never null)
getSignedInfo
()

Returns the signed info of this XMLSignature.

public void
sign(XMLSignContext
the signing context
signContext
)

Signs this XMLSignature.

public boolean

Returns:

true if the signature passed core validation, otherwise false
validate
(XMLValidateContext
the validating context
validateContext
)

Validates the signature according to the core validation processing rules.

Inherited from javax.xml.crypto.XMLStructure:
isFeatureSupported

Field Detail

XMLNSback to summary
public static final String XMLNS

The XML Namespace URI of the W3C Recommendation for XML-Signature Syntax and Processing.

Method Detail

getIdback to summary
public String getId()

Returns the optional Id of this XMLSignature.

Returns:String

the Id (may be null if not specified)

getKeyInfoback to summary
public KeyInfo getKeyInfo()

Returns the key info of this XMLSignature.

Returns:KeyInfo

the key info (may be null if not specified)

getKeySelectorResultback to summary
public KeySelectorResult getKeySelectorResult()

Returns the result of the KeySelector, if specified, after this XMLSignature has been signed or validated.

Returns:KeySelectorResult

the key selector result, or null if a key selector has not been specified or this XMLSignature has not been signed or validated

getObjectsback to summary
public List<XMLObject> getObjects()

Returns an unmodifiable list of XMLObjects contained in this XMLSignature.

Returns:List<XMLObject>

an unmodifiable list of XMLObjects (may be empty but never null)

getSignatureValueback to summary
public XMLSignature.SignatureValue getSignatureValue()

Returns the signature value of this XMLSignature.

Returns:XMLSignature.SignatureValue

the signature value

getSignedInfoback to summary
public SignedInfo getSignedInfo()

Returns the signed info of this XMLSignature.

Returns:SignedInfo

the signed info (never null)

signback to summary
public void sign(XMLSignContext signContext) throws MarshalException, XMLSignatureException

Signs this XMLSignature.

If this method throws an exception, this XMLSignature and the signContext parameter will be left in the state that it was in prior to the invocation.

Parameters
signContext:XMLSignContext

the signing context

Exceptions
MarshalException:
if an exception occurs while marshalling
XMLSignatureException:
if an unexpected exception occurs while generating the signature
ClassCastException:
if the type of signContext is not compatible with this XMLSignature
NullPointerException:
if signContext is null
validateback to summary
public boolean validate(XMLValidateContext validateContext) throws XMLSignatureException

Validates the signature according to the core validation processing rules. This method validates the signature using the existing state, it does not unmarshal and reinitialize the contents of the XMLSignature using the location information specified in the context.

This method only validates the signature the first time it is invoked. On subsequent invocations, it returns a cached result.

Parameters
validateContext:XMLValidateContext

the validating context

Returns:boolean

true if the signature passed core validation, otherwise false

Exceptions
XMLSignatureException:
if an unexpected error occurs during validation that prevented the validation operation from completing
ClassCastException:
if the type of validateContext is not compatible with this XMLSignature
NullPointerException:
if validateContext is null
javax.xml.crypto.dsig back to summary

public Interface XMLSignature.SignatureValue

extends XMLStructure
Known Direct Implementers
org.jcp.xml.dsig.internal.dom.DOMXMLSignature.DOMSignatureValue

A representation of the XML SignatureValue element as defined in the W3C Recommendation for XML-Signature Syntax and Processing. The XML Schema Definition is defined as:
  <element name="SignatureValue" type="ds:SignatureValueType"/>
    <complexType name="SignatureValueType">
      <simpleContent>
        <extension base="base64Binary">
          <attribute name="Id" type="ID" use="optional"/>
        </extension>
      </simpleContent>
    </complexType>
Authors
Sean Mullan, JSR 105 Expert Group

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the Id attribute (may be null if not specified)
getId
()

Returns the optional Id attribute of this SignatureValue, which permits this element to be referenced from elsewhere.

public byte[]

Returns:

the signature value (may be null if the XMLSignature has not been signed yet). Each invocation of this method returns a new clone of the array to prevent subsequent modification.
getValue
()

Returns the signature value of this SignatureValue.

public boolean

Returns:

true if the signature was validated successfully; false otherwise
validate
(XMLValidateContext
the validating context
validateContext
)

Validates the signature value.

Inherited from javax.xml.crypto.XMLStructure:
isFeatureSupported

Method Detail

getIdback to summary
public String getId()

Returns the optional Id attribute of this SignatureValue, which permits this element to be referenced from elsewhere.

Returns:String

the Id attribute (may be null if not specified)

getValueback to summary
public byte[] getValue()

Returns the signature value of this SignatureValue.

Returns:byte[]

the signature value (may be null if the XMLSignature has not been signed yet). Each invocation of this method returns a new clone of the array to prevent subsequent modification.

validateback to summary
public boolean validate(XMLValidateContext validateContext) throws XMLSignatureException

Validates the signature value. This method performs a cryptographic validation of the signature calculated over the SignedInfo of the XMLSignature.

This method only validates the signature the first time it is invoked. On subsequent invocations, it returns a cached result.

Parameters
validateContext:XMLValidateContext

the validating context

Returns:boolean

true if the signature was validated successfully; false otherwise

Exceptions
XMLSignatureException:
if an unexpected exception occurs while validating the signature
NullPointerException:
if validateContext is null