public final class Encryptor extends EncryptionHandler
Encryptor class encrypts Document Object Model (DOM)
elements in an XML document.Decryptorm_DOMdocument, m_XMLEInit| Constructor and Description |
|---|
Encryptor(XMLEInit initializer)
Creates a new XML DOM Document.
|
Encryptor(XMLEInit initializer,
java.io.InputStream document)
Parses an XML document to a DOM tree and initializes the Toolkit to encrypt DOM
elements within the document.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
encrypt()
Encrypts all DOM elements for which at least one recipient has been set.
|
org.w3c.dom.Element |
encryptBinary(java.io.InputStream input)
Encrypts an external binary file referenced by an
Inputstream. |
org.w3c.dom.Element |
encryptBinary(java.lang.String plaintextURI)
Encrypts an external binary file referenced by
plaintextURI. |
org.w3c.dom.Element |
encryptContent(org.w3c.dom.Element element)
Encrypts only the content of a DOM element, not the element's tag and attributes.
|
org.w3c.dom.Element |
encryptElement(org.w3c.dom.Element element)
Encrypts a DOM element.
|
byte[] |
getCipherText(java.lang.String ciphertextURI)
Returns the cipher text corresponding to the given ciphertext URI
after encryption.
|
java.lang.String |
getEncryptedDataBaseID()
Accessor method to rerieve base ID of the <EncryptedData> element.
|
org.w3c.dom.Element |
getEncryptedDataElement(java.io.InputStream binaryInputStream)
Returns the lt;EncryptedData> element referred to by the
Inputstream. |
org.w3c.dom.Element |
getEncryptedDataElement(java.lang.String externalBinaryURI)
Returns the <EncryptedData> element referred to by the
URI references to binary data.
|
EncryptedElementSet[] |
getEncryptedElementSets()
Returns
EncryptedElementSets that contain all the <EncryptedData>
and <EncryptedKey> DOM elements the Toolkit created when it encrypted
the document. |
java.lang.String |
getEncryptedKeyAlgorithm()
Retrieves the algorithm that encrypts <EncryptedKey> elements.
|
java.lang.String |
getEncryptedKeyBaseID()
Accessor method to retrieve the <EncryptedKey> element's base ID.
|
X509Certificate[] |
getRecipients(java.lang.Object element)
Identifies the recipients for whom a particular DOM element has been encrypted
all the users who will be able to decrypt the element.
|
java.lang.String |
getSymmetricAlgorithm()
Identifies the symmetric algorithm currently in effect.
|
java.lang.String |
getSymmetricAlgorithm(org.w3c.dom.Element element)
Identifies the symmetric algorithm that encrypted a particular <EncryptedData>
DOM element.
|
Trustmanager |
getTrustmanager()
Returns the
Trustmanager that was set in a particular
Encryptor instance. |
protected void |
setCipherText(java.lang.String ciphertextURI,
byte[] ciphertext)
Stores the cipher text corresponding to the given ciphertext URI.
|
void |
setCipherURI(java.lang.Object element,
java.lang.String ciphertextURI)
Specifies the cipher text URI for this element.
|
void |
setContentOnly(org.w3c.dom.Element element,
boolean contentOnly)
Determines whether an entire DOM element (including opening and closing tags) or just
the content of a DOM element is to be encrypted.
|
void |
setEncryptedDataBaseID(java.lang.String baseID)
Sets the <EncryptedData> base ID.
|
void |
setEncryptedDataId(java.lang.Object element,
java.lang.String id)
Lets the application specify a particular value for the Id attribute of an
<EncryptedData> DOM element.
|
void |
setEncryptedKeyAlgorithm(java.lang.String algorithm)
Sets the algorithm that encrypts <EncryptedKey> DOM elements.
|
void |
setEncryptedKeyBaseID(java.lang.String baseID)
Sets the <EncryptedKey> base ID.
|
void |
setKeyEncryptionKey(java.lang.Object element,
javax.crypto.SecretKey keyEncryptionKey,
byte[] id)
Sets a key encryption key that will be used to encrypt this particular
DOM element.
|
void |
setRecipient(java.lang.Object element,
X509Certificate certificate)
Sets a certificate whose public key will be used to encrypt this particular
DOM element or its content.
|
void |
setSymmetricAlgorithm(java.lang.String algorithm)
Sets the symmetric algorithm.
|
void |
setTrustmanager(Trustmanager trustmanager)
Initializes this instance with a
Trustmanager,
which can validate encryption certificates. |
void |
setTrustmanager(User validator)
Deprecated.
use setTrustmanager(
Trustmanager trustmanager) instead. |
org.w3c.dom.Document |
toDocument()
Returns the DOM tree of the document.
|
void |
updateContent(org.w3c.dom.Element element)
Replaces the unencrypted element content with an <EncryptedData>
element called after the
encryptContent method. |
void |
updateElement(org.w3c.dom.Element element)
Replaces the unencrypted element or content with an <EncryptedData>
element called after encryption.
|
getDocument, isValidated, toInputStream, toOutputStreampublic Encryptor(XMLEInit initializer) throws EncryptionHandlerException, EncryptorException
initializer - a reference to an XMLEInit object.EncryptionHandlerException - if creating the DOM Document fails.EncryptorExceptionpublic Encryptor(XMLEInit initializer, java.io.InputStream document) throws EncryptionHandlerException
initializer - a reference to an XMLEInit object.document - an InputStream that provides the XML document to be encrypted.EncryptionHandlerException - if parsing the document without validation failspublic void setTrustmanager(User validator) throws UserNotLoggedInException
Trustmanager trustmanager) instead.Encryptor with a trust manager.
This method provides a means of validating encryption certificates, by providing capabilities such as secure access to a root of trust and certificate revocation checking.
validator - a logged in UserUserNotLoggedInException - if the User is not already
logged inpublic void setTrustmanager(Trustmanager trustmanager)
Trustmanager,
which can validate encryption certificates.
trustmanager - a TrustmanagerUserNotLoggedInException - if the User is not already
logged inpublic Trustmanager getTrustmanager()
Trustmanager that was set in a particular
Encryptor instance.
Trustmanagerpublic java.lang.String getEncryptedKeyAlgorithm()
The algorithm can be set using the setEncryptedKeyAlgorithm
method.
setEncryptedKeyAlgorithm(java.lang.String)public void setEncryptedKeyAlgorithm(java.lang.String algorithm)
throws EncryptorException
algorithm - a URN that identifies the algorithm. Allowed values are
found in the com.entrust.toolkit.xencrypt.init.XMLEConstants
class.EncryptorExceptionXMLEConstants.ALGORITHM_RSA,
XMLEConstants.ALGORITHM_RSA_OAEP,
XMLEConstants.ALGORITHM_AES_256_KEY_WRAP,
XMLEConstants.ALGORITHM_AES_128_KEY_WRAP,
XMLEConstants.ALGORITHM_AES_192_KEY_WRAP,
XMLEConstants.ALGORITHM_3DES_KEY_WRAPpublic void setKeyEncryptionKey(java.lang.Object element,
javax.crypto.SecretKey keyEncryptionKey,
byte[] id)
throws EncryptionHandlerException
The method encrypts the DOM element, its content, or an inputstream or URI referring to the external binary data. If the element already has other key encryption keys, the method adds this one. If the element already has this key, the method does nothing.
element - an Element to be encrypted for the recipient,
or an Inputstream or a URI string reference
to the external binary datakeyEncryptionKey - the key encryption keyid - the id of the key encryption keyEncryptorException - if the certificate cannot be validated.EncryptionHandlerExceptionEncryptedElementSet.addRecipient(iaik.x509.X509Certificate)public java.lang.String getSymmetricAlgorithm()
The algorithm can be set using the setSymmetricAlgorithm
method.
setSymmetricAlgorithm(java.lang.String)public java.lang.String getSymmetricAlgorithm(org.w3c.dom.Element element)
throws EncryptorException
This method is provided for convenience, since the application can specify the encryption algorithm itself.
element - an <EncryptedData> DOM elementEncryptorException - if element parameter is not an
<EncryptedData> DOM element.setSymmetricAlgorithm(java.lang.String)public void setSymmetricAlgorithm(java.lang.String algorithm)
This method does the following:
The setSymmetricAlgorithm method has no effect on the following:
EncryptedElementSets that were created before invoking this method.algorithm - a String that specifies the symmetric algorithm. Allowed
values are found in the com.entrust.toolkit.xencrypt.init.XMLEConstants
classXMLEConstants.ALGORITHM_3DES,
XMLEConstants.ALGORITHM_AES_256,
XMLEConstants.ALGORITHM_AES_192,
XMLEConstants.ALGORITHM_AES_128public java.lang.String getEncryptedKeyBaseID()
The base ID is used by an application to specify a value for the Id attribute of
<EncryptedKey> DOM elements created by the Encryptor instance
that calls this method.
String that contains the base ID valuesetEncryptedKeyBaseID(java.lang.String)public void setEncryptedKeyBaseID(java.lang.String baseID)
throws EncryptorException
The base ID determines the value of the Id attribute assigned to
<EncryptedKey> DOM elements created by the Encryptor
instance that calls this method.
As new <EncryptedKey> DOM elements are created, the Encryptor assigns
them Ids numbered sequentially from zero, using the base ID as a common String.
For example, if the base ID is set to "EK", then <EncryptedKey> elements will have Id
values as follows: Id="EK0", Id="EK1", and so on.
XMLEConstants.ENCRYPTEDKEY_BASE_ID.baseId that makes
all the Ids within a particular document unique.baseID - a String common to all Ids as described aboveEncryptorException - if the 'id' argument is not a unique ID value within
this DOM documentXMLEConstants.ENCRYPTEDKEY_BASE_ID,
getEncryptedKeyBaseID()public java.lang.String getEncryptedDataBaseID()
The base ID is used by an application to specify a value for
the Id attribute of <EncryptedData> DOM elements created
by the Encryptor instance that calls this method.
String that contains the base ID valuesetEncryptedDataBaseID(java.lang.String)public void setEncryptedDataBaseID(java.lang.String baseID)
throws EncryptorException
The base ID determines the value of the Id attribute assigned to the
<EncryptedData> DOM elements created by the Encryptor
instance that calls this method.
As new <EncryptedData> DOM elements are created, the Encryptor assigns
them Id values numbered sequentially starting from zero. The Encryptor uses
this base ID as a prefix. For example, if the base ID is set to "ED", then
<EncryptedData> DOM elements will receive Id values: Id="ED0",
Id="ED1", and so on.
baseID - a String common to all Ids as described aboveEncryptorException - if 'id' is not a unique attribute value within this documentsetEncryptedDataId(java.lang.Object, java.lang.String),
setEncryptedKeyBaseID(java.lang.String)public org.w3c.dom.Element encryptElement(org.w3c.dom.Element element)
throws EncryptorException
When this method returns, the DOM element has been replaced
by an <EncryptedData> DOM element whose Type attribute has the value "Element". Its
Id attribute has a value that is generated internally by the Toolkit, unless the application
has specified a particular value for the Id by invoking the methods
setEncryptedDataBaseID or setEncryptedDataId.
element - is the DOM Element to be encryptedEncryptorExceptionsetEncryptedDataBaseID(java.lang.String)public void updateElement(org.w3c.dom.Element element)
throws EncryptionHandlerException
element - the DOM Element to be encryptedEncryptionHandlerExceptionpublic org.w3c.dom.Element encryptContent(org.w3c.dom.Element element)
throws EncryptorException
When this method returns, the content has been replaced by an <EncryptedData> DOM
element whose Type attribute has the value "CONTENT".
The Id attribute of the <EncryptedData> DOM element is created internally
by the Toolkit, unless the application has specified a particular value by calling
setEncryptedDataBaseID or setEncryptedDataId.
element - is the DOM Element to be encryptedEncryptorExceptionsetContentOnly(org.w3c.dom.Element, boolean)public void updateContent(org.w3c.dom.Element element)
throws EncryptionHandlerException
encryptContent method.element - the DOM element to be encryptedEncryptionHandlerExceptionpublic org.w3c.dom.Element encryptBinary(java.lang.String plaintextURI)
throws EncryptorException
plaintextURI.
plaintextURI - a URI reference to binary dataEncryptorExceptionpublic org.w3c.dom.Element encryptBinary(java.io.InputStream input)
throws EncryptorException
Inputstream.
input - an Inputstream reference to binary dataEncryptorExceptionpublic boolean encrypt()
throws EncryptorException
The recipient may have been set directly on the DOM element or attached to an
EncryptedElementSet instance to which the DOM element belongs.
When this method returns, all of the DOM elements have been replaced by
<EncryptedData> DOM elements.
For each element, this method encrypts either the element and its content
or just the content, depending on what the application specified in a prior
call to the setContentOnly(Element, boolean) method. If
setContentOnly(Element, boolean) has not been called, this method throws
an exception.
EncryptorException - if the encryption of an element fails for some reasonsetContentOnly(org.w3c.dom.Element, boolean),
setRecipient(java.lang.Object, iaik.x509.X509Certificate),
EncryptedElementSet.addRecipient(X509Certificate)public void setRecipient(java.lang.Object element,
X509Certificate certificate)
throws EncryptorException
If the element already has other recipients, the method adds this one. If the element already has this recipient, the method does nothing.
element - is an Element to be encrypted for the recipientcertificate - is the recipient's encryption certificateEncryptorException - if the certificate cannot be validated.EncryptedElementSet.addRecipient(iaik.x509.X509Certificate)public void setEncryptedDataId(java.lang.Object element,
java.lang.String id)
throws EncryptorException
This method is called before the element is encrypted. The <EncryptedData> DOM element is created later, when the element is encrypted.
element - is the DOM element to be encryptedid - the value to be set for the Id attribute of the
<EncryptedData> DOM elementEncryptorException - if 'id' is not a unique attribute value within the document or
if the element has not been specified as one to be
encrypted, i.e. if setRecipient()
has not yet been called on this element.setRecipient(java.lang.Object, iaik.x509.X509Certificate),
setEncryptedKeyBaseID(java.lang.String)public void setCipherURI(java.lang.Object element,
java.lang.String ciphertextURI)
throws EncryptorException
element - the XML document element or external binary data to be encryptedciphertextURI - the URI at which the application will write the ciphertext
externally to the <EncryptedData> element. This URI
is pointed to in the <CipherReference> element.EncryptorExceptionpublic byte[] getCipherText(java.lang.String ciphertextURI)
ciphertextURI - the uri at which the application will write the ciphertext
externally to the <EncryptedData> element. This URI
is pointed to in the <CipherReference> element.protected void setCipherText(java.lang.String ciphertextURI,
byte[] ciphertext)
ciphertextURI - the URI at which the application will write the ciphertext
externally to the EncryptedData element. This URI
is pointed to in the <CipherReference> element.ciphertext - The result ciphertext after encryption.public void setContentOnly(org.w3c.dom.Element element,
boolean contentOnly)
throws EncryptorException
Two kinds of element encryption are defined by the XENC proposal: the encryption of the entire element, and the encryption of the contents of the element.
Calling setContentOnly(element, true) encrypts the
child elements of the element argument. Calling
setContentOnly(element, false), encrypts the opening and closing
tags of the element argument, its attributes, and all of its children.
For example, given the following XML element, parent:
<parent name=Mary>
<childElementA />
<childElementB>cat</childElementB>
<childElementC>dog</childElementC>
</parent>
setContentOnly(element, true) (element argument
references the parent element in the XML fragment) encrypts the
childElementA, childElementB, and
childElementC elements, their opening and closing tags and
their contents.
setContentOnly(element, false) (element argument
references the parent element in the XML fragment) encrypts the
parent element's opening and closing tags, its name
attribute and the childElementA, childElementB, and
childElementC elements, their opening and closing tags and
their contents.
EncryptorException - if this setting has already been specified or
if the DOM element has not been initialized as
an element to be encrypted, either by adding a
recipient to the element or adding the DOM element
into an EncryptedElementSet.encryptContent(org.w3c.dom.Element)public org.w3c.dom.Document toDocument()
This method is usually called after one or more encryption operations to return the encrypted document.
EncryptionHandler.toOutputStream(java.io.OutputStream),
EncryptionHandler.toInputStream()public X509Certificate[] getRecipients(java.lang.Object element) throws EncryptorException
The method returns all the recipients of the EncryptedElementSet of which
this <EncryptedData> DOM element is a member.
X509Certificate of each recipientEncryptorException - if element is not an <EncryptedData> DOM elementpublic EncryptedElementSet[] getEncryptedElementSets()
EncryptedElementSets that contain all the <EncryptedData>
and <EncryptedKey> DOM elements the Toolkit created when it encrypted
the document. The document should be encrypted before this method is invoked.
The application might use this method when it must access the <EncryptedData> and <EncryptedKey> elements using methods of the standard DOM API. For example, the application might move an <EncryptedKey> element to a different position in the encrypted document, in order to conform to a particular DTD or XML schema.
EncryptedElementSet.getEncryptedDatas(),
EncryptedElementSet.getEncryptedKeys()public org.w3c.dom.Element getEncryptedDataElement(java.lang.String externalBinaryURI)
throws EncryptionHandlerException
Used for external binary data encryption.
Element that corresponds to the externalBinaryURI.EncryptionHandlerExceptionpublic org.w3c.dom.Element getEncryptedDataElement(java.io.InputStream binaryInputStream)
throws EncryptionHandlerException
Inputstream.
Used for external binary data encryption.
Element that corresponds to the Inputstream.EncryptionHandlerException