org.apache.xml.security.encryption
Class XMLCipher

java.lang.Object
  extended byorg.apache.xml.security.encryption.XMLCipher

public class XMLCipher
extends java.lang.Object

XMLCipher encrypts and decrypts the contents of Documents, Elements and Element contents. It was designed to resemble javax.crypto.Cipher in order to facilitate understanding of its functioning.

Author:
Axl Mattheus (Sun Microsystems), Christian Geuer-Pollmann

Field Summary
static java.lang.String AES_128
           
static java.lang.String AES_128_KeyWrap
           
static java.lang.String AES_192
           
static java.lang.String AES_192_KeyWrap
           
static java.lang.String AES_256
           
static java.lang.String AES_256_KeyWrap
           
static java.lang.String BASE64_ENCODING
           
static int DECRYPT_MODE
           
static java.lang.String DIFFIE_HELLMAN
           
static int ENCRYPT_MODE
           
static java.lang.String EXCL_XML_N14C
           
static java.lang.String EXCL_XML_N14C_WITH_COMMENTS
           
static java.lang.String N14C_XML
           
static java.lang.String N14C_XML_WITH_COMMENTS
           
static java.lang.String RIPEMD_160
           
static java.lang.String RSA_OAEP
           
static java.lang.String RSA_v1dot5
           
static java.lang.String SHA1
           
static java.lang.String SHA256
           
static java.lang.String SHA512
           
static java.lang.String TRIPLEDES
           
static java.lang.String TRIPLEDES_KeyWrap
           
static int UNWRAP_MODE
           
static int WRAP_MODE
           
static java.lang.String XML_DSIG
           
 
Method Summary
 org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Document source)
          Process a DOM Document node.
 org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Element element)
          Process a DOM Element node.
 org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Element element, boolean content)
          Process the contents of a DOM Element node.
 EncryptedData encryptData(org.w3c.dom.Document context, org.w3c.dom.Element element)
          Returns an EncryptedData interface.
 EncryptedKey encryptKey(org.w3c.dom.Document context, org.w3c.dom.Element element)
          Decrypts an EncryptedKey object.
static XMLCipher getInstance(java.lang.String transformation)
          Returns an XMLCipher that implements the specified transformation and operates on the specified context document.
static XMLCipher getInstance(java.lang.String transformation, java.lang.String provider)
          Returns an XMLCipher that implements the specified transformation and operates on the specified context document.
 void init(int opmode, java.security.Key key)
          Initializes this cipher with a key.
 EncryptedData loadEncryptedData(org.w3c.dom.Document context, org.w3c.dom.Element element)
          Returns an EncryptedData interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRIPLEDES

public static final java.lang.String TRIPLEDES
See Also:
Constant Field Values

AES_128

public static final java.lang.String AES_128
See Also:
Constant Field Values

AES_256

public static final java.lang.String AES_256
See Also:
Constant Field Values

AES_192

public static final java.lang.String AES_192
See Also:
Constant Field Values

RSA_v1dot5

public static final java.lang.String RSA_v1dot5
See Also:
Constant Field Values

RSA_OAEP

public static final java.lang.String RSA_OAEP
See Also:
Constant Field Values

DIFFIE_HELLMAN

public static final java.lang.String DIFFIE_HELLMAN
See Also:
Constant Field Values

TRIPLEDES_KeyWrap

public static final java.lang.String TRIPLEDES_KeyWrap
See Also:
Constant Field Values

AES_128_KeyWrap

public static final java.lang.String AES_128_KeyWrap
See Also:
Constant Field Values

AES_256_KeyWrap

public static final java.lang.String AES_256_KeyWrap
See Also:
Constant Field Values

AES_192_KeyWrap

public static final java.lang.String AES_192_KeyWrap
See Also:
Constant Field Values

SHA1

public static final java.lang.String SHA1
See Also:
Constant Field Values

SHA256

public static final java.lang.String SHA256
See Also:
Constant Field Values

SHA512

public static final java.lang.String SHA512
See Also:
Constant Field Values

RIPEMD_160

public static final java.lang.String RIPEMD_160
See Also:
Constant Field Values

XML_DSIG

public static final java.lang.String XML_DSIG
See Also:
Constant Field Values

N14C_XML

public static final java.lang.String N14C_XML
See Also:
Constant Field Values

N14C_XML_WITH_COMMENTS

public static final java.lang.String N14C_XML_WITH_COMMENTS
See Also:
Constant Field Values

EXCL_XML_N14C

public static final java.lang.String EXCL_XML_N14C
See Also:
Constant Field Values

EXCL_XML_N14C_WITH_COMMENTS

public static final java.lang.String EXCL_XML_N14C_WITH_COMMENTS
See Also:
Constant Field Values

BASE64_ENCODING

public static final java.lang.String BASE64_ENCODING
See Also:
Constant Field Values

ENCRYPT_MODE

public static final int ENCRYPT_MODE
See Also:
Constant Field Values

DECRYPT_MODE

public static final int DECRYPT_MODE
See Also:
Constant Field Values

UNWRAP_MODE

public static final int UNWRAP_MODE
See Also:
Constant Field Values

WRAP_MODE

public static final int WRAP_MODE
See Also:
Constant Field Values
Method Detail

getInstance

public static XMLCipher getInstance(java.lang.String transformation)
                             throws XMLEncryptionException
Returns an XMLCipher that implements the specified transformation and operates on the specified context document.

If the default provider package supplies an implementation of the requested transformation, an instance of Cipher containing that implementation is returned. If the transformation is not available in the default provider package, other provider packages are searched.

NOTE1: The transformation name does not follow the same pattern as that oulined in the Java Cryptography Extension Reference Guide but rather that specified by the XML Encryption Syntax and Processing document. The rational behind this is to make it easier for a novice at writing Java Encryption software to use the library.

NOTE2: getInstance() does not follow the same pattern regarding exceptional conditions as that used in javax.crypto.Cipher. Instead, it only throws an XMLEncryptionException which wraps an underlying exception. The stack trace from the exception should be self explanitory.

Parameters:
transformation - the name of the transformation, e.g., XMLCipher.TRIPLEDES which is shorthand for "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
Throws:
XMLEncryptionException.
XMLEncryptionException
See Also:
Cipher.getInstance(java.lang.String)

getInstance

public static XMLCipher getInstance(java.lang.String transformation,
                                    java.lang.String provider)
                             throws XMLEncryptionException
Returns an XMLCipher that implements the specified transformation and operates on the specified context document.

Parameters:
transformation - the name of the transformation, e.g., XMLCipher.TRIPLEDES which is shorthand for "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
provider - the JCE provider that supplies the transformation
Throws:
XMLEncryptionException.
XMLEncryptionException

init

public void init(int opmode,
                 java.security.Key key)
          throws XMLEncryptionException
Initializes this cipher with a key.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

Parameters:
opmode - the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)
key -
Throws:
XMLEncryptionException
See Also:
Cipher.init(int, java.security.Key)

doFinal

public org.w3c.dom.Document doFinal(org.w3c.dom.Document context,
                                    org.w3c.dom.Document source)
                             throws XMLEncryptionException
Process a DOM Document node. The processing depends on the initialization parameters of init().

Parameters:
context - the context Document.
source - the Document to be encrypted or decrypted.
Returns:
the processed Document.
Throws:
XMLEnccryptionException - to indicate any exceptional conditions.
XMLEncryptionException

doFinal

public org.w3c.dom.Document doFinal(org.w3c.dom.Document context,
                                    org.w3c.dom.Element element)
                             throws XMLEncryptionException
Process a DOM Element node. The processing depends on the initialization parameters of init().

Parameters:
context - the context Document.
element - the Element to be encrypted.
Returns:
the processed Document.
Throws:
XMLEnccryptionException - to indicate any exceptional conditions.
XMLEncryptionException

doFinal

public org.w3c.dom.Document doFinal(org.w3c.dom.Document context,
                                    org.w3c.dom.Element element,
                                    boolean content)
                             throws XMLEncryptionException
Process the contents of a DOM Element node. The processing depends on the initialization parameters of init().

Parameters:
context - the context Document.
element - the Element which contents is to be encrypted.
Returns:
the processed Document.
Throws:
XMLEnccryptionException - to indicate any exceptional conditions.
XMLEncryptionException

encryptData

public EncryptedData encryptData(org.w3c.dom.Document context,
                                 org.w3c.dom.Element element)
                          throws XMLEncryptionException
Returns an EncryptedData interface. Use this operation if you want to have full control over the contents of the EncryptedData structure.

Parameters:
context - the context Document.
element - the Element that will be encrypted.
Throws:
XMLEncryptionException.
XMLEncryptionException

loadEncryptedData

public EncryptedData loadEncryptedData(org.w3c.dom.Document context,
                                       org.w3c.dom.Element element)
                                throws XMLEncryptionException
Returns an EncryptedData interface. Use this operation if you want to load an EncryptedData structure from a DOM structure and manipulate the contents

Parameters:
context - the context Document.
element - the Element that will be loaded
Throws:
XMLEncryptionException.
XMLEncryptionException

encryptKey

public EncryptedKey encryptKey(org.w3c.dom.Document context,
                               org.w3c.dom.Element element)
                        throws XMLEncryptionException
Decrypts an EncryptedKey object.

Throws:
XMLEncryptionException