public interface XMLSignature extends XMLStructure
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.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
XMLSignature.SignatureValue
A representation of the XML
SignatureValue element as
defined in the
W3C Recommendation for XML-Signature Syntax and Processing. |
| Modifier and Type | Field and Description |
|---|---|
static String |
XMLNS
The XML Namespace URI of the W3C Recommendation for XML-Signature
Syntax and Processing.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getId()
Returns the optional Id of this
XMLSignature. |
KeyInfo |
getKeyInfo()
Returns the key info of this
XMLSignature. |
KeySelectorResult |
getKeySelectorResult()
Returns the result of the
KeySelector, if specified, after
this XMLSignature has been signed or validated. |
List |
getObjects()
|
XMLSignature.SignatureValue |
getSignatureValue()
Returns the signature value of this
XMLSignature. |
SignedInfo |
getSignedInfo()
Returns the signed info of this
XMLSignature. |
void |
sign(XMLSignContext signContext)
Signs this
XMLSignature. |
boolean |
validate(XMLValidateContext validateContext)
Validates the signature according to the
core validation processing rules.
|
isFeatureSupportedstatic final String XMLNS
boolean validate(XMLValidateContext validateContext) throws XMLSignatureException
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.
validateContext - the validating contexttrue if the signature passed core validation,
otherwise falseClassCastException - if the type of validateContext
is not compatible with this XMLSignatureNullPointerException - if validateContext is
nullXMLSignatureException - if an unexpected error occurs during
validation that prevented the validation operation from completingKeyInfo getKeyInfo()
XMLSignature.null if not specified)SignedInfo getSignedInfo()
XMLSignature.null)List getObjects()
XMLObjects (may be empty
but never null)String getId()
XMLSignature.null if not specified)XMLSignature.SignatureValue getSignatureValue()
XMLSignature.void sign(XMLSignContext signContext) throws MarshalException, XMLSignatureException
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.
signContext - the signing contextClassCastException - if the type of signContext is
not compatible with this XMLSignatureNullPointerException - if signContext is
nullMarshalException - if an exception occurs while marshallingXMLSignatureException - if an unexpected exception occurs while
generating the signatureKeySelectorResult getKeySelectorResult()
KeySelector, if specified, after
this XMLSignature has been signed or validated.null if a key
selector has not been specified or this XMLSignature
has not been signed or validated Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.