public class EncryptedElementSet
extends java.lang.Object
EncryptedElementSet class allows an application to define a set of DOM
elements to be encrypted for a group of recipients.
An application specifies the DOM elements to be encrypted for a set of recipients by performing the following steps:
EncryptedElementSetEncryptedElementSet instanceEncryptedElementSet instance
All DOM elements in a particular EncryptedElementSet are encrypted by the
same symmetric key. This means that relatively few private key operations are required when
decrypting (fewer <EncryptedKey> elements are needed), and the encrypted document
is smaller in size. For these reasons, an application might use an
EncryptedElementSet even when it encrypts a document for just one recipient.
Internally, the Toolkit manages details that arise when encrypting several DOM elements with the
same symmetric key and encrypting that key material for multiple recipients. For example, the
Toolkit does not permit the application to add a DOM element into more than one
EncryptedElementSet instance each set receives its own unique symmetric key and
the recipients who can decrypt a particular DOM element are defined explicitly (by the application,
when it attaches recipients to a set). In addition, the Toolkit generates a fresh
initialization vector (IV) as it encrypts each element in a set, even though the elements
share symmetric key material.
EncryptedElementSet class assists the application in managing the encrypt
use case and is not needed when decrypting.| Constructor and Description |
|---|
EncryptedElementSet(Encryptor encryptor)
Creates an empty
EncryptedElementSet that has no recipients. |
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(org.w3c.dom.Element element)
Adds a DOM element to the set of DOM elements to be encrypted (or whose
content is to be encrypted) for the recipients of this
EncryptedElementSet. |
void |
addElement(java.io.InputStream input)
Adds an
InputStream to the data set to be encrypted
for the recipients of this EncryptedElementSet. |
void |
addElement(java.lang.String plaintextURI)
Adds a plaintext URI to the data set to be encrypted for the
recipients of this
EncryptedElementSet. |
void |
addKeyEncryptionKey(javax.crypto.SecretKey keyEncryptionKey,
byte[] id)
Adds a key encryption key (KEK) to a set of elements.
|
void |
addRecipient(X509Certificate certificate)
Adds a recipient to a set of elements.
|
void |
encrypt()
Encrypts the DOM elements in this
EncryptedElementSet,
creating <EncryptedKey> and <EncryptedData> DOM elements
as required. |
org.w3c.dom.Element[] |
getEncryptedDatas()
Retrieves the <EncryptedData> DOM elements that were created by the Toolkit when
the DOM elements in this
EncryptedElementSet were encrypted. |
org.w3c.dom.Element[] |
getEncryptedKeys()
Retrieves the <EncryptedKey> DOM elements that were created by the Toolkit when the
DOM elements in this
EncryptedElementSet were encrypted. |
X509Certificate[] |
getRecipients()
Identifies the recipients attached to this set.
|
boolean |
isEncrypted()
Indicates whether or not the set of elements has been encrypted.
|
public EncryptedElementSet(Encryptor encryptor) throws EncryptedElementSetException
EncryptedElementSet that has no recipients.
The symmetric algorithm for an EncryptedElementSet instance is the
algorithm in effect when the set is instantiated.
encryptor - the Encryptor that encrypts the setEncryptedElementSetException - if the set cannot be instantiatedEncryptor.setSymmetricAlgorithm(java.lang.String)public boolean isEncrypted()
public org.w3c.dom.Element[] getEncryptedKeys()
throws EncryptedElementSetException
EncryptedElementSet were encrypted.
EncryptedElementSetException - if the EncryptedElementSet has not yet
been encryptedpublic org.w3c.dom.Element[] getEncryptedDatas()
throws EncryptedElementSetException
EncryptedElementSet were encrypted.
EncryptedElementSetException - if the EncryptedElementSet has not yet
been encrypted yetpublic X509Certificate[] getRecipients()
X509Certificate of each recipient, or null if there are no recipientspublic void addElement(org.w3c.dom.Element element)
throws EncryptedElementSetException
EncryptedElementSet.
element - is the DOM Element to be addedEncryptedElementSetException - if adding the element fails for any reasonEncryptor.setContentOnly(org.w3c.dom.Element, boolean)public void addElement(java.lang.String plaintextURI)
throws EncryptedElementSetException
EncryptedElementSet.
plaintextURI - the plaintext URI to be addedEncryptedElementSetException - if adding the URI fails for any reasonpublic void addElement(java.io.InputStream input)
throws EncryptedElementSetException
InputStream to the data set to be encrypted
for the recipients of this EncryptedElementSet.
input - the InputStream to be addedEncryptedElementSetException - if adding the URI fails for any reasonpublic void addRecipient(X509Certificate certificate) throws EncryptedElementSetException
If the element set has other recipients,the addRecipient method
adds this one. If the element set already had this recipient, the
method does nothing.
An <EncryptedKey> DOM element encrypts the set for a particular recipient. The
public key comes from the certificate provided as an argument of the method
(validated internally before being used), and the encryption method is the
<EncryptedKey> algorithm in effect when this method is invoked. The algorithm
is determined by setEncryptedKeyAlgorithm(String algorithm) and is
RSA encryption with either PKCS#1 v1.5 or PKCS#1 v2.0 (OAEP).
certificate - an encryption certificateEncryptedElementSetException - is the certificate is not validEncryptor.setEncryptedKeyAlgorithm(java.lang.String)public void addKeyEncryptionKey(javax.crypto.SecretKey keyEncryptionKey,
byte[] id)
throws EncryptedElementSetException
If the element set has other KEKs,the addKeyEncryptionKey
method adds this one. If the element set already had this KEK, the
method does nothing.
An <EncryptedKey> DOM element encrypts the set with a particular key encryption key.
The key encryption key and its id are provided as arguments, and the encryption method
is the <EncryptedKey> algorithm in effect when this method is invoked. The algorithm
is determined by setEncryptedKeyAlgorithm(String algorithm) and is one of the
key wrap algorithms.
keyEncryptionKey - n key encryption keyid - the id of key encryption keyEncryptedElementSetException - error
when adding the key encryption keyEncryptor.setEncryptedKeyAlgorithm(java.lang.String)public void encrypt()
throws EncryptedElementSetException
EncryptedElementSet,
creating <EncryptedKey> and <EncryptedData> DOM elements
as required.
After this method has been called, the application can retrieve the <EncryptedData>
and <EncryptedKey> DOM elements by invoking getEncryptedDatas
or getEncryptedKeys.
EncryptedElementSetExceptiongetEncryptedDatas(),
getEncryptedKeys()