com.rsa.swsj.encryption
Class XMLEncryption

java.lang.Object
  extended bycom.rsa.swsj.XMLSecurityOperation
      extended bycom.rsa.swsj.encryption.XMLEncryption

public final class XMLEncryption
extends XMLSecurityOperation

This is the main class for XML encryption. It stores all the nessesary data, such as an encryption algorithm or encryption keys, and performs encryption and decryption operations.


Field Summary

static java.lang.String

ALG_ENCRYPTION_AES128

AES 128-bit encryption algorithm.

static java.lang.String

ALG_ENCRYPTION_AES256

AES 256-bit encryption algorithm.

static java.lang.String

ALG_ENCRYPTION_RC4

RC4 128-bit encryption algorithm.

static java.lang.String

ALG_ENCRYPTION_TRIPLE_DES

Triple DES encryption algorithm.

static java.lang.String

ALG_KEY_WRAP_AES128

AES 128-bit key wrapping algorithm for XML Encryption.

static java.lang.String

ALG_KEY_WRAP_AES256

AES 256-bit key wrapping algorithm for XML Encryption.

static java.lang.String

ALG_KEY_WRAP_TRIPLE_DES

Triple DES key wrapping algorithm for XML Encryption.

static java.lang.String

ALG_TRANSPORT_RSA

RSA key transport algorithm for XML Encryption.

static java.lang.String

ALG_TRANSPORT_RSA_OAEP

RSA with OAEP key transport algorithm for XML Encryption.

static int

CONTENT_ENCRYPTION

Specifies that the EncryptedData element contains data of element content.

static int

DATA_ENCRYPTION

Specifies that the EncryptedData element contains arbitrary data.

static int

ELEMENT_ENCRYPTION

Specifies that the EncryptedData element contains data of the type element.

 
Constructor Summary
XMLEncryption(SWSJContext context)

This is the default constructor.

XMLEncryption(SWSJContext context, java.lang.String reference, java.security.PublicKey pubKey)

This constructor should be used in simple cases.

 
Method Summary

 void

addReference(Reference reference)

Adds a Reference.

 byte[]

getCipherData()

Gets the encrypted data.

 java.lang.String

getEncoding()

Gets the encoding format of the decrypted data.

 java.lang.String

getEncryptionMethod()

Gets the encryption method.

 java.lang.String

getMimeType()

Returns the mime type of the decrypted data.

 javax.crypto.SecretKey

getSecretKey()

Gets the secret key used to encrypt or decrypt data.

 int

getType()

Gets the encryption type.

 javax.crypto.SecretKey

getWrappingKey()

Gets the key used for wrapping the encryption key.

 void

setEncoding(java.lang.String encoding)

Sets the encoding format to encoding.

 void

setEncryptionMethod(java.lang.String encryptionMethod)

Sets the encryption method to encryptionMethod.

 void

setMimeType(java.lang.String mimeType)

Sets the mime type to mimeType Call this method only when encrypting the document.

 void

setReferences(Reference[] references)

Sets the array of references.

 void

setSecretKey(javax.crypto.SecretKey secretKey)

Sets the secret key that will be used to encrypt or decrypt data.

 void

setTransportKey(java.security.PrivateKey transportKey)

Sets the transport key which may decrypt the secret key that encrypted the encrypted data.

 void

setType(int type)

Sets the encryption type to type.

 void

setWrappingKey(javax.crypto.SecretKey wrapKey)

Sets the key used for wrapping the encryption key.

 
Methods inherited from class com.rsa.swsj.XMLSecurityOperation
getContext, getId, getNamespacePrefix, getOutputStream, getParameters, getReferences, getStatusInfo, getTimestamp, setExpirationTime, setId, setLocation, setNamespacePrefix, setOutputStream, setParameters, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ELEMENT_ENCRYPTION

public static final int ELEMENT_ENCRYPTION
Specifies that the EncryptedData element contains data of the type element.

See Also:
Constant Field Values

CONTENT_ENCRYPTION

public static final int CONTENT_ENCRYPTION
Specifies that the EncryptedData element contains data of element content.

See Also:
Constant Field Values

DATA_ENCRYPTION

public static final int DATA_ENCRYPTION
Specifies that the EncryptedData element contains arbitrary data.

See Also:
Constant Field Values

ALG_ENCRYPTION_TRIPLE_DES

public static final java.lang.String ALG_ENCRYPTION_TRIPLE_DES
Triple DES encryption algorithm.

See Also:
Constant Field Values

ALG_ENCRYPTION_RC4

public static final java.lang.String ALG_ENCRYPTION_RC4
RC4 128-bit encryption algorithm.

See Also:
Constant Field Values

ALG_ENCRYPTION_AES128

public static final java.lang.String ALG_ENCRYPTION_AES128
AES 128-bit encryption algorithm.

See Also:
Constant Field Values

ALG_ENCRYPTION_AES256

public static final java.lang.String ALG_ENCRYPTION_AES256
AES 256-bit encryption algorithm.

See Also:
Constant Field Values

ALG_TRANSPORT_RSA

public static final java.lang.String ALG_TRANSPORT_RSA
RSA key transport algorithm for XML Encryption.

See Also:
Constant Field Values

ALG_TRANSPORT_RSA_OAEP

public static final java.lang.String ALG_TRANSPORT_RSA_OAEP
RSA with OAEP key transport algorithm for XML Encryption.

See Also:
Constant Field Values

ALG_KEY_WRAP_TRIPLE_DES

public static final java.lang.String ALG_KEY_WRAP_TRIPLE_DES
Triple DES key wrapping algorithm for XML Encryption.

See Also:
Constant Field Values

ALG_KEY_WRAP_AES128

public static final java.lang.String ALG_KEY_WRAP_AES128
AES 128-bit key wrapping algorithm for XML Encryption.

See Also:
Constant Field Values

ALG_KEY_WRAP_AES256

public static final java.lang.String ALG_KEY_WRAP_AES256
AES 256-bit key wrapping algorithm for XML Encryption.

See Also:
Constant Field Values
Constructor Detail

XMLEncryption

public XMLEncryption(SWSJContext context)
              throws EncryptionException
This is the default constructor. It creates an empty XMLEncryption object initialized only with a context.

Parameters:
context - An object that collects a number of common parameters and state variables; for example, JCE provider.
Throws:
EncryptionException - If context is invalid.

XMLEncryption

public XMLEncryption(SWSJContext context,
                     java.lang.String reference,
                     java.security.PublicKey pubKey)
              throws EncryptionException
This constructor should be used in simple cases. It creates an XMLEncryption object and sets all nessesary values. By default the entire element is encrypted, and XMLEncryption.ALG_ENCRYPTION_AES256 is used for encryption.

Parameters:
context - An object that collects a number of common parameters and state variables.
reference - The data to encrypt.
pubKey - The transport key used to encrypt the encryption key.
Throws:
EncryptionException - If any parameter is invalid.
Method Detail

setSecretKey

public void setSecretKey(javax.crypto.SecretKey secretKey)
                  throws EncryptionException
Sets the secret key that will be used to encrypt or decrypt data.

Parameters:
secretKey - A key to encrypt or decrypt data
Throws:
EncryptionException - If this key's algorithm is not supported.

getSecretKey

public javax.crypto.SecretKey getSecretKey()
Gets the secret key used to encrypt or decrypt data.

Returns:
The secret key.

setWrappingKey

public void setWrappingKey(javax.crypto.SecretKey wrapKey)
                    throws EncryptionException
Sets the key used for wrapping the encryption key.

Parameters:
wrapKey - The wrapping key.
Throws:
EncryptionException

getWrappingKey

public javax.crypto.SecretKey getWrappingKey()
Gets the key used for wrapping the encryption key.

Returns:
The wrapping key

setEncryptionMethod

public void setEncryptionMethod(java.lang.String encryptionMethod)
                         throws EncryptionException
Sets the encryption method to encryptionMethod.

Parameters:
encryptionMethod - A String value that specifies the algorithm used for encryption and decryption.
Throws:
EncryptionException - If the given encryption method value is not supported.

getEncryptionMethod

public java.lang.String getEncryptionMethod()
Gets the encryption method.

Returns:
A String containing the algorithm used for encryption and decryption.

setType

public void setType(int type)
             throws InvalidParameterException
Sets the encryption type to type.

Call this method only when encrypting the document.

Specified by:
setType in class XMLSecurityOperation
Parameters:
type - An integer containing the value of the encryption type, defined in this class.
Throws:
InvalidParameterException

getType

public int getType()
Gets the encryption type.

Specified by:
getType in class XMLSecurityOperation
Returns:
An integer containing the value of the encryption type, defined in this class.

setMimeType

public void setMimeType(java.lang.String mimeType)
Sets the mime type to mimeType

Call this method only when encrypting the document.

Parameters:
mimeType - A string containing the mime type of the original data to encrypt.

getMimeType

public java.lang.String getMimeType()
Returns the mime type of the decrypted data.

Returns:
A String containing the mime type.

setEncoding

public void setEncoding(java.lang.String encoding)
Sets the encoding format to encoding.

Call this method only when encrypting the document.

Parameters:
encoding - A string specifying the encoding format for the original data to encrypt.

getEncoding

public java.lang.String getEncoding()
Gets the encoding format of the decrypted data.

Returns:
A String containing the encoding format.

getCipherData

public byte[] getCipherData()
Gets the encrypted data.

Returns:
The encrypted data as a byte array.

setReferences

public void setReferences(Reference[] references)
                   throws InvalidParameterException
Sets the array of references. For encryption, the only allowed transform is XPATH which is used to locate the data to be encrypted. All other transforms will be ignored.

Overrides:
setReferences in class XMLSecurityOperation
Parameters:
references - An array of references.
Throws:
InvalidParameterException - If any of the references is null.

addReference

public void addReference(Reference reference)
                  throws InvalidParameterException
Adds a Reference. For encryption, the only allowed transform is XPATH which is used to locate the data to be encrypted.

Overrides:
addReference in class XMLSecurityOperation
Parameters:
reference - The reference to add.
Throws:
InvalidParameterException - If the reference is null.

setTransportKey

public void setTransportKey(java.security.PrivateKey transportKey)
Sets the transport key which may decrypt the secret key that encrypted the encrypted data. This operation does not report any errors.

Parameters:
transportKey - The transport key to use for decryption.