XMLDSigner

public interface XMLDSigner

This interface defines a standard way to have the document signed. Different classes will implement the interface using different library behind.

Author:kcyee

Methods

addDocument

public void addDocument(String uri, InputStream is, String contentType)

Adds a reference to a document attachment to the signature.

Parameters:
  • uri – the URI of the document attachment
  • is – the input stream of the content of the document
  • contentType – the content type of the document

getElement

public Element getElement()

Gets the DOM element of the signature generated.

Returns:the DOM element of the signature

setEnvelope

public void setEnvelope(Document doc)

Set the envelope to host the Signature element. That is the XML document where the Signature element to be added. The digital signature here will always be an enveloped signature. The envelope will be included in the process of signing.

Parameters:
  • doc – the XML document to host the Signature element
Throws:

setTrustAnchor

public void setTrustAnchor(CompositeKeyStore ks)

Sets the trust anchor for verfication of certificate path.

Parameters:
  • ks – the keystore providing the trusted certificates

sign

public void sign(CompositeKeyStore ks, String alias, char[] password)

Signs the envelope and documents by using the specified key in the keystore.

Parameters:
  • ks – the keystore holding the key for signing
  • alias – the alias of the key for signing
  • password – the password for accessing the key for signing
Throws:
  • SignException – when there is any error in the processing of signing

verify

public boolean verify()

Verifies the signature in the envelope passed in, which may reference the documents specified using the addDocument method.

Throws:
  • VerifyException – when there is any error in the processing of verification
Returns:

true if the signature can be verified successfully, false if otherwise.