|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.xml.security.encryption.XMLCipher
XMLCipher
encrypts and decrypts the contents of
Document
s, Element
s and Element
contents. It was designed to resemble javax.crypto.Cipher
in
order to facilitate understanding of its functioning.
Field Summary | |
static java.lang.String |
AES_128
AES 128 Cipher |
static java.lang.String |
AES_128_KeyWrap
AES 128 Cipher KeyWrap |
static java.lang.String |
AES_192
AES 192 Cipher |
static java.lang.String |
AES_192_KeyWrap
AES 192 Cipher KeyWrap |
static java.lang.String |
AES_256
AES 256 Cipher |
static java.lang.String |
AES_256_KeyWrap
AES 256 Cipher KeyWrap |
static java.lang.String |
BASE64_ENCODING
Base64 encoding |
static int |
DECRYPT_MODE
DECRYPT Mode |
static java.lang.String |
DIFFIE_HELLMAN
DIFFIE_HELLMAN Cipher |
static int |
ENCRYPT_MODE
ENCRYPT Mode |
static java.lang.String |
EXCL_XML_N14C
N14C_XML excluisve |
static java.lang.String |
EXCL_XML_N14C_WITH_COMMENTS
N14C_XML exclusive with commetns |
static java.lang.String |
N14C_XML
N14C_XML |
static java.lang.String |
N14C_XML_WITH_COMMENTS
N14C_XML with comments |
static java.lang.String |
RIPEMD_160
RIPEMD Cipher |
static java.lang.String |
RSA_OAEP
RSA OAEP Cipher |
static java.lang.String |
RSA_v1dot5
RSA 1.5 Cipher |
static java.lang.String |
SHA1
SHA1 Cipher |
static java.lang.String |
SHA256
SHA256 Cipher |
static java.lang.String |
SHA512
SHA512 Cipher |
static java.lang.String |
TRIPLEDES
Triple DES EDE (192 bit key) in CBC mode |
static java.lang.String |
TRIPLEDES_KeyWrap
Triple DES EDE (192 bit key) in CBC mode KEYWRAP |
static int |
UNWRAP_MODE
UNWRAP Mode |
static int |
WRAP_MODE
WRAP Mode |
static java.lang.String |
XML_DSIG
XML Signature NS |
Method Summary | |
AgreementMethod |
createAgreementMethod(java.lang.String algorithm)
Create an AgreementMethod object |
CipherData |
createCipherData(int type)
Create a CipherData object |
CipherReference |
createCipherReference(java.lang.String uri)
Create a CipherReference object |
CipherValue |
createCipherValue(java.lang.String value)
Create a CipherValue element |
EncryptedData |
createEncryptedData(int type,
java.lang.String value)
Creates an EncryptedData Element . |
EncryptedKey |
createEncryptedKey(int type,
java.lang.String value)
Creates an EncryptedKey Element . |
EncryptionMethod |
createEncryptionMethod(java.lang.String algorithm)
Create an EncryptionMethod object |
EncryptionProperties |
createEncryptionProperties()
Create an EncryptionProperties element |
EncryptionProperty |
createEncryptionProperty()
Create a new EncryptionProperty element |
ReferenceList |
createReferenceList(int type)
Create a new ReferenceList object |
Transforms |
createTransforms()
Create a new Transforms object |
Transforms |
createTransforms(org.w3c.dom.Document doc)
Create a new Transforms object Because the handling of Transforms is currently done in the signature code, the creation of a Transforms object requires a context document. |
java.security.Key |
decryptKey(EncryptedKey encryptedKey)
Decrypt a key from a passed in EncryptedKey structure. |
java.security.Key |
decryptKey(EncryptedKey encryptedKey,
java.lang.String algorithm)
Decrypt a key from a passed in EncryptedKey structure |
byte[] |
decryptToByteArray(org.w3c.dom.Element element)
Decrypt an EncryptedData element to a byte array When passed in an EncryptedData node, returns the decryption as a byte array. |
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. |
EncryptedData |
encryptData(org.w3c.dom.Document context,
org.w3c.dom.Element element,
boolean contentMode)
Returns an EncryptedData interface. |
EncryptedData |
encryptData(org.w3c.dom.Document context,
java.lang.String type,
java.io.InputStream serializedData)
Returns an EncryptedData interface. |
EncryptedKey |
encryptKey(org.w3c.dom.Document doc,
java.security.Key key)
Encrypts a key to an EncryptedKey structure |
EncryptedData |
getEncryptedData()
Get the EncryptedData being build Returns the EncryptedData being built during an ENCRYPT operation. |
EncryptedKey |
getEncryptedKey()
Get the EncryptedData being build Returns the EncryptedData being built during an ENCRYPT operation. |
static XMLCipher |
getInstance()
Returns an XMLCipher that implements no specific
transformation, and can therefore only be used for decrypt or
unwrap operations where the encryption method is defined in the
EncryptionMethod element. |
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 canon)
Returns an XMLCipher that implements the specified
transformation, operates on the specified context document and serializes
the document with the specified canonicalization algorithm before it
encrypts the document. |
static XMLCipher |
getProviderInstance(java.lang.String provider)
Returns an XMLCipher that implements no specific
transformation, and can therefore only be used for decrypt or
unwrap operations where the encryption method is defined in the
EncryptionMethod element. |
static XMLCipher |
getProviderInstance(java.lang.String transformation,
java.lang.String provider)
Returns an XMLCipher that implements the specified
transformation and operates on the specified context document. |
static XMLCipher |
getProviderInstance(java.lang.String transformation,
java.lang.String provider,
java.lang.String canon)
Returns an XMLCipher that implements the specified
transformation, operates on the specified context document and serializes
the document with the specified canonicalization algorithm before it
encrypts the 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. |
EncryptedKey |
loadEncryptedKey(org.w3c.dom.Document context,
org.w3c.dom.Element element)
Returns an EncryptedKey interface. |
EncryptedKey |
loadEncryptedKey(org.w3c.dom.Element element)
Returns an EncryptedKey interface. |
org.w3c.dom.Element |
martial(org.w3c.dom.Document context,
EncryptedData encryptedData)
Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriate EncryptedData |
org.w3c.dom.Element |
martial(org.w3c.dom.Document context,
EncryptedKey encryptedKey)
Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriate EncryptedKey |
org.w3c.dom.Element |
martial(EncryptedData encryptedData)
Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriate EncryptedData
|
org.w3c.dom.Element |
martial(EncryptedKey encryptedKey)
Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriate EncryptedKey
|
void |
setKEK(java.security.Key kek)
Set a Key Encryption Key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String TRIPLEDES
public static final java.lang.String AES_128
public static final java.lang.String AES_256
public static final java.lang.String AES_192
public static final java.lang.String RSA_v1dot5
public static final java.lang.String RSA_OAEP
public static final java.lang.String DIFFIE_HELLMAN
public static final java.lang.String TRIPLEDES_KeyWrap
public static final java.lang.String AES_128_KeyWrap
public static final java.lang.String AES_256_KeyWrap
public static final java.lang.String AES_192_KeyWrap
public static final java.lang.String SHA1
public static final java.lang.String SHA256
public static final java.lang.String SHA512
public static final java.lang.String RIPEMD_160
public static final java.lang.String XML_DSIG
public static final java.lang.String N14C_XML
public static final java.lang.String N14C_XML_WITH_COMMENTS
public static final java.lang.String EXCL_XML_N14C
public static final java.lang.String EXCL_XML_N14C_WITH_COMMENTS
public static final java.lang.String BASE64_ENCODING
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
public static final int UNWRAP_MODE
public static final int WRAP_MODE
Method Detail |
public static XMLCipher getInstance(java.lang.String transformation) throws XMLEncryptionException
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 outlined 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 explanatory.
transformation
- the name of the transformation, e.g.,
XMLCipher.TRIPLEDES
which is shorthand for
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
XMLEncryptionException
Cipher.getInstance(java.lang.String)
public static XMLCipher getInstance(java.lang.String transformation, java.lang.String canon) throws XMLEncryptionException
XMLCipher
that implements the specified
transformation, operates on the specified context document and serializes
the document with the specified canonicalization algorithm before it
encrypts the document.
transformation
- the name of the transformation, e.g.,
XMLCipher.TRIPLEDES
which is
shorthand for
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc"canon
- the name of the c14n algorithm, if
null
use standard serializer
XMLEncryptionException
public static XMLCipher getProviderInstance(java.lang.String transformation, java.lang.String provider) throws XMLEncryptionException
XMLCipher
that implements the specified
transformation and operates on the specified context document.
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
XMLEncryptionException
public static XMLCipher getProviderInstance(java.lang.String transformation, java.lang.String provider, java.lang.String canon) throws XMLEncryptionException
XMLCipher
that implements the specified
transformation, operates on the specified context document and serializes
the document with the specified canonicalization algorithm before it
encrypts the document.
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 transformationcanon
- the name of the c14n algorithm, if
null
use standard serializer
XMLEncryptionException
public static XMLCipher getInstance() throws XMLEncryptionException
XMLCipher
that implements no specific
transformation, and can therefore only be used for decrypt or
unwrap operations where the encryption method is defined in the
EncryptionMethod
element.
XMLEncryptionException
public static XMLCipher getProviderInstance(java.lang.String provider) throws XMLEncryptionException
XMLCipher
that implements no specific
transformation, and can therefore only be used for decrypt or
unwrap operations where the encryption method is defined in the
EncryptionMethod
element.
Allows the caller to specify a provider that will be used for
cryptographic operations.
provider
- the JCE provider that supplies the transformation
XMLEncryptionException
public void init(int opmode, java.security.Key key) throws XMLEncryptionException
The cipher is initialized for one of the following four operations:
encryption, decryption, key wrapping or key unwrapping, depending on the
value of opmode.
For WRAP and ENCRYPT modes, this also initialises the internal
EncryptedKey or EncryptedData (with a CipherValue)
structure that will be used during the ensuing operations. This
can be obtained (in order to modify KeyInfo elements etc. prior to
finalising the encryption) by calling
getEncryptedData()
or getEncryptedKey()
.
opmode
- the operation mode of this cipher (this is one of the
following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)key
-
XMLEncryptionException
Cipher.init(int, java.security.Key)
public EncryptedData getEncryptedData()
public EncryptedKey getEncryptedKey()
public void setKEK(java.security.Key kek)
The Key Encryption Key (KEK) is used for encrypting/decrypting EncryptedKey elements. By setting this separately, the XMLCipher class can know whether a key applies to the data part or wrapped key part of an encrypted object.
kek
- The key to use for de/encrypting key datapublic org.w3c.dom.Element martial(EncryptedData encryptedData)
EncryptedData
Note: This should only be used in cases where the context document has been passed in via a call to doFinal.
encryptedData
- EncryptedData object to martial
Element
representing the passed in
objectpublic org.w3c.dom.Element martial(EncryptedKey encryptedKey)
EncryptedKey
Note: This should only be used in cases where the context document has been passed in via a call to doFinal.
encryptedKey
- EncryptedKey object to martial
Element
representing the passed in
objectpublic org.w3c.dom.Element martial(org.w3c.dom.Document context, EncryptedData encryptedData)
EncryptedData
context
- The document that will own the returned nodesencryptedData
- EncryptedData object to martial
Element
representing the passed in
objectpublic org.w3c.dom.Element martial(org.w3c.dom.Document context, EncryptedKey encryptedKey)
EncryptedKey
context
- The document that will own the created nodesencryptedKey
- EncryptedKey object to martial
Element
representing the passed in
objectpublic org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Document source) throws java.lang.Exception
Document
node. The processing depends on the
initialization parameters of init()
.
context
- the context Document
.source
- the Document
to be encrypted or decrypted.
Document
.
java.lang.Exception
- to indicate any exceptional conditions.public org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Element element) throws java.lang.Exception
Element
node. The processing depends on the
initialization parameters of init()
.
context
- the context Document
.element
- the Element
to be encrypted.
Document
.
java.lang.Exception
- to indicate any exceptional conditions.public org.w3c.dom.Document doFinal(org.w3c.dom.Document context, org.w3c.dom.Element element, boolean content) throws java.lang.Exception
Element
node. The processing
depends on the initialization parameters of
init()
.
context
- the context Document
.element
- the Element
which contents is to be
encrypted.content
-
Document
.
java.lang.Exception
- to indicate any exceptional conditions.public EncryptedData encryptData(org.w3c.dom.Document context, org.w3c.dom.Element element) throws java.lang.Exception
EncryptedData
interface. Use this operation if
you want to have full control over the contents of the
EncryptedData
structure.
this does not change the source document in any way.
context
- the context Document
.element
- the Element
that will be encrypted.
EncryptedData
java.lang.Exception
public EncryptedData encryptData(org.w3c.dom.Document context, java.lang.String type, java.io.InputStream serializedData) throws java.lang.Exception
EncryptedData
interface. Use this operation if
you want to have full control over the serialization of the element
or element content.
This does not change the source document in any way.
context
- the context Document
.type
- a URI identifying type information about the plaintext form
of the encrypted content (may be null
)serializedData
- the serialized data
EncryptedData
java.lang.Exception
public EncryptedData encryptData(org.w3c.dom.Document context, org.w3c.dom.Element element, boolean contentMode) throws java.lang.Exception
EncryptedData
interface. Use this operation if
you want to have full control over the contents of the
EncryptedData
structure.
this does not change the source document in any way.
context
- the context Document
.element
- the Element
that will be encrypted.contentMode
- true
to encrypt element's content only,
false
otherwise
EncryptedData
java.lang.Exception
public EncryptedData loadEncryptedData(org.w3c.dom.Document context, org.w3c.dom.Element element) throws XMLEncryptionException
EncryptedData
interface. Use this operation if
you want to load an EncryptedData
structure from a DOM
structure and manipulate the contents
context
- the context Document
.element
- the Element
that will be loaded
EncryptedData
XMLEncryptionException
public EncryptedKey loadEncryptedKey(org.w3c.dom.Document context, org.w3c.dom.Element element) throws XMLEncryptionException
EncryptedKey
interface. Use this operation if
you want to load an EncryptedKey
structure from a DOM
structure and manipulate the contents.
context
- the context Document
.element
- the Element
that will be loaded
EncryptedKey
XMLEncryptionException
public EncryptedKey loadEncryptedKey(org.w3c.dom.Element element) throws XMLEncryptionException
EncryptedKey
interface. Use this operation if
you want to load an EncryptedKey
structure from a DOM
structure and manipulate the contents.
Assumes that the context document is the document that owns the element
element
- the Element
that will be loaded
EncryptedKey
XMLEncryptionException
public EncryptedKey encryptKey(org.w3c.dom.Document doc, java.security.Key key) throws XMLEncryptionException
doc
- the Context document that will be used to general DOMkey
- Key to encrypt (will use previously set KEK to
perform encryption
EncryptedKey
XMLEncryptionException
public java.security.Key decryptKey(EncryptedKey encryptedKey, java.lang.String algorithm) throws XMLEncryptionException
encryptedKey
- Previously loaded EncryptedKey that needs
to be decrypted.algorithm
- Algorithm for the decryption
XMLEncryptionException
public java.security.Key decryptKey(EncryptedKey encryptedKey) throws XMLEncryptionException
encryptedKey
- Previously loaded EncryptedKey that needs
to be decrypted.
XMLEncryptionException
public byte[] decryptToByteArray(org.w3c.dom.Element element) throws XMLEncryptionException
element
-
XMLEncryptionException
public EncryptedData createEncryptedData(int type, java.lang.String value) throws XMLEncryptionException
EncryptedData
Element
.
The newEncryptedData and newEncryptedKey methods create fairly complete
elements that are immediately useable. All the other create* methods
return bare elements that still need to be built upon.
An EncryptionMethod will still need to be added however
type
- Either REFERENCE_TYPE or VALUE_TYPE - defines what kind of
CipherData this EncryptedData will contain.value
- the Base 64 encoded, encrypted text to wrap in the
EncryptedData
or the URI to set in the CipherReference
(usage will depend on the type
EncryptedData
Element
.
XMLEncryptionException
public EncryptedKey createEncryptedKey(int type, java.lang.String value) throws XMLEncryptionException
EncryptedKey
Element
.
The newEncryptedData and newEncryptedKey methods create fairly complete
elements that are immediately useable. All the other create* methods
return bare elements that still need to be built upon.
An EncryptionMethod will still need to be added however
type
- Either REFERENCE_TYPE or VALUE_TYPE - defines what kind of
CipherData this EncryptedData will contain.value
- the Base 64 encoded, encrypted text to wrap in the
EncryptedKey
or the URI to set in the CipherReference
(usage will depend on the type
EncryptedKey
Element
.
XMLEncryptionException
public AgreementMethod createAgreementMethod(java.lang.String algorithm)
algorithm
- Algorithm of the agreement method
AgreementMethod
public CipherData createCipherData(int type)
type
- Type of this CipherData (either VALUE_TUPE or
REFERENCE_TYPE)
CipherData
public CipherReference createCipherReference(java.lang.String uri)
uri
- The URI that the reference will refer
CipherReference
public CipherValue createCipherValue(java.lang.String value)
value
- The value to set the ciphertext to
CipherValue
public EncryptionMethod createEncryptionMethod(java.lang.String algorithm)
algorithm
- Algorithm for the encryption
EncryptionMethod
public EncryptionProperties createEncryptionProperties()
EncryptionProperties
public EncryptionProperty createEncryptionProperty()
EncryptionProperty
public ReferenceList createReferenceList(int type)
type
- ReferenceList.DATA_REFERENCE or ReferenceList.KEY_REFERENCE
ReferenceList
public Transforms createTransforms()
Note: A context document must have been set elsewhere (possibly via a call to doFinal). If not, use the createTransforms(Document) method.
Transforms
public Transforms createTransforms(org.w3c.dom.Document doc)
doc
- Document that will own the created Transforms node
Transforms
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |