public class XMLDocumentSigner
extends java.lang.Object
| Constructor and Description |
|---|
XMLDocumentSigner(org.w3c.dom.Document d)
Creates a new XML Document Signer out of a given Document; the caller guarantees the Document can handle
namespaces
|
XMLDocumentSigner(java.io.File xmlFile)
Creates a new XML Document Signer, using the contents of a File as the XML Document
|
XMLDocumentSigner(java.lang.String xml)
Creates a new XML Document Signer, using an XML document represented by the given String.
|
| Modifier and Type | Method and Description |
|---|---|
static java.security.KeyPair |
getKeypair(java.security.KeyStore ks,
java.lang.String alias,
char[] passphrase)
Helper method; retrieves a named public/private keypair from a KeyStore.
|
boolean |
hasSignature()
Determines whether this document has a signature tag
|
boolean |
save(java.io.File dest)
Saves the Document, as manipulated by this class, as a File
|
org.w3c.dom.Document |
sign(java.lang.String machineId,
java.security.KeyPair keys)
Given a keypair, signs this document and adds the public key to the signature tag
|
org.w3c.dom.Document |
sign(java.lang.String machineId,
java.security.PublicKey publicKey,
java.security.PrivateKey privateKey)
Given a pair of keys, signs this document and adds the public key to the signature tag
|
org.w3c.dom.Document |
stripSignature()
Removes the signature tag from this document if they are present
|
java.lang.String |
toString()
Produces an XML String representation of the document
|
boolean |
validate(Keystore truststore)
Validates the document using the public keys of the
Certificates in truststore |
boolean |
validate(java.security.PublicKey... allowedKeys)
Validates the signature tag on the document
|
public XMLDocumentSigner(java.lang.String xml)
throws java.lang.Exception
xml - The XML document as a Stringjava.lang.Exception - If the xml document could not be loadedpublic XMLDocumentSigner(java.io.File xmlFile)
throws java.lang.Exception
xmlFile - The XML document filejava.lang.Exception - If the xml document could not be loadedpublic XMLDocumentSigner(org.w3c.dom.Document d)
d - the xml documentpublic org.w3c.dom.Document sign(java.lang.String machineId,
java.security.KeyPair keys)
keys - KeyPair The public/private keypairpublic static java.security.KeyPair getKeypair(java.security.KeyStore ks,
java.lang.String alias,
char[] passphrase)
throws java.security.NoSuchAlgorithmException,
java.security.UnrecoverableEntryException,
java.security.KeyStoreException
ks - The KeyStorealias - The name of the keypassphrase - The passphrase (if necessary)java.security.NoSuchAlgorithmExceptionjava.security.UnrecoverableEntryExceptionjava.security.KeyStoreExceptionpublic org.w3c.dom.Document sign(java.lang.String machineId,
java.security.PublicKey publicKey,
java.security.PrivateKey privateKey)
publicKey - PublicKey The public keyprivateKey - PrivateKey The private keypublic boolean save(java.io.File dest)
dest - The destination filetrue if the document was saved, otherwise falsepublic org.w3c.dom.Document stripSignature()
public boolean hasSignature()
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean validate(Keystore truststore) throws java.security.cert.CertificateException, java.io.FileNotFoundException, java.io.IOException, java.security.KeyStoreException, java.security.NoSuchAlgorithmException
Certificates in truststoretruststore - The trust storejava.security.cert.CertificateException - If there was a problem with the certificatejava.io.FileNotFoundException - If the truststore's file could't be loadedjava.io.IOException - If a generic IO exception occurredjava.security.KeyStoreException - If a problem occurred during keystore loadingjava.security.NoSuchAlgorithmException - If the keystore couldn't be loadedpublic boolean validate(java.security.PublicKey... allowedKeys)
allowedKeys - the PublicKeys whose signatures will be considered validtrue if the document was signed by one of the keys listed & the signature is valid, otherwise
falseCopyright © 2014. All Rights Reserved.