public class XMLDocumentSigner extends Object
| Constructor and Description |
|---|
XMLDocumentSigner(Document d)
Creates a new XML Document Signer out of a given Document; the caller guarantees the Document can handle
namespaces
|
XMLDocumentSigner(File xmlFile)
Creates a new XML Document Signer, using the contents of a File as the XML Document
|
XMLDocumentSigner(String xml)
Creates a new XML Document Signer, using an XML document represented by the given String.
|
| Modifier and Type | Method and Description |
|---|---|
static KeyPair |
getKeypair(KeyStore ks,
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(File dest)
Saves the Document, as manipulated by this class, as a File
|
Document |
sign(String machineId,
KeyPair keys)
Given a keypair, signs this document and adds the public key to the signature tag
|
Document |
sign(String machineId,
PublicKey publicKey,
PrivateKey privateKey)
Given a pair of keys, signs this document and adds the public key to the signature tag
|
Document |
stripSignature()
Removes the signature tag from this document if they are present
|
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(PublicKey... allowedKeys)
Validates the signature tag on the document
|
public XMLDocumentSigner(String xml) throws Exception
xml - The XML document as a StringException - If the xml document could not be loadedpublic XMLDocumentSigner(File xmlFile) throws Exception
xmlFile - The XML document fileException - If the xml document could not be loadedpublic XMLDocumentSigner(Document d)
d - the xml documentpublic Document sign(String machineId, KeyPair keys)
keys - KeyPair The public/private keypairpublic static KeyPair getKeypair(KeyStore ks, String alias, char[] passphrase) throws NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException
ks - The KeyStorealias - The name of the keypassphrase - The passphrase (if necessary)NoSuchAlgorithmExceptionUnrecoverableEntryExceptionKeyStoreExceptionpublic Document sign(String machineId, PublicKey publicKey, PrivateKey privateKey)
publicKey - PublicKey The public keyprivateKey - PrivateKey The private keypublic boolean save(File dest)
dest - The destination filetrue if the document was saved, otherwise falsepublic Document stripSignature()
public boolean hasSignature()
public String toString()
public boolean validate(Keystore truststore) throws CertificateException, FileNotFoundException, IOException, KeyStoreException, NoSuchAlgorithmException
Certificates in truststoretruststore - The trust storeCertificateException - If there was a problem with the certificateFileNotFoundException - If the truststore's file could't be loadedIOException - If a generic IO exception occurredKeyStoreException - If a problem occurred during keystore loadingNoSuchAlgorithmException - If the keystore couldn't be loadedpublic boolean validate(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.