Class XMLCipher
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.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAES 128 Cipherstatic final StringAES 128 GCM Cipherstatic final StringAES 128 Cipher KeyWrapstatic final StringAES 192 Cipherstatic final StringAES 192 GCM Cipherstatic final StringAES 192 Cipher KeyWrapstatic final StringAES 256 Cipherstatic final StringAES 256 GCM Cipherstatic final StringAES 256 Cipher KeyWrapprivate StringURI of algorithm that is being used for cryptographic operationstatic final StringBase64 encodingstatic final StringCAMELLIA 128 Cipherstatic final StringCAMELLIA 128 Cipher KeyWrapstatic final StringCAMELLIA 192 Cipherstatic final StringCAMELLIA 192 Cipher KeyWrapstatic final StringCAMELLIA 256 Cipherstatic final StringCAMELLIA 256 Cipher KeyWrapprivate CanonicalizerHolds c14n to serialize, if initialized then _always_ use this c14n to serializeprivate intMode that the XMLCipher object is operating inprivate CipherCipher created during initialisation that is used for encryptionprivate DocumentUsed for creation of DOM nodes in WRAP and ENCRYPT modesstatic final intDECRYPT Modestatic final StringDIFFIE_HELLMAN Cipherprivate Stringprivate EncryptedDataprivate EncryptedKeyprivate static final Stringstatic final intENCRYPT Modestatic final StringN14C_XML exclusivestatic final StringN14C_XML exclusive with commentsprivate XMLCipher.FactoryInstance of factory used to create XML Encryption objectsprivate static final booleanprivate List<KeyResolverSpi> List of internal KeyResolvers for DECRYPT and UNWRAP modes.private KeyLocal copy of the kek (used to decrypt EncryptedKeys during a DECRYPT_MODE operationprivate KeyLocal copy of user's keyprivate static final org.slf4j.Loggerstatic final StringN14C_XMLstatic final StringN14C_XML with commentsstatic final StringN14C_PHYSICAL preserve the physical representationprivate StringCryptographic provider requested by callerstatic final StringRIPEMD Cipherstatic final StringRSA OAEP Cipherstatic final StringRSA OAEP Cipherstatic final StringRSA 1.5 Cipherprivate booleanstatic final StringSEED 128 Cipherstatic final StringSEED 128 Cipher KeyWrapprivate SerializerSerializer class for going to/from UTF-8static final StringSHA1 Cipherstatic final StringSHA256 Cipherstatic final StringSHA512 Cipherstatic final StringTriple DES EDE (192 bit key) in CBC modestatic final StringTriple DES EDE (192 bit key) in CBC mode KEYWRAPstatic final intUNWRAP Modestatic final intWRAP Modestatic final StringXML Signature NS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate AlgorithmParameterSpecconstructBlockCipherParameters(String algorithm, byte[] iv) Build anAlgorithmParameterSpecinstance used to initialize aCipherinstance for block cipher encryption and decryption.private CipherconstructCipher(String algorithm, String digestAlgorithm) Construct a Cipher objectprivate CipherconstructCipher(String algorithm, String digestAlgorithm, Exception nsae) private OAEPParameterSpecconstructOAEPParameters(String encryptionAlgorithm, String digestAlgorithm, String mgfAlgorithm, byte[] oaepParams) Construct an OAEPParameterSpec object from the given parameterscreateAgreementMethod(String algorithm) Create an AgreementMethod objectcreateCipherData(int type) Create a CipherData objectCreate a CipherReference objectcreateCipherValue(String value) Create a CipherValue elementcreateEncryptedData(int type, String value) Creates anEncryptedDataElement.createEncryptedKey(int type, String value) Creates anEncryptedKeyElement.createEncryptionMethod(String algorithm) Create an EncryptionMethod objectCreate an EncryptionProperties elementCreate a new EncryptionProperty elementcreateReferenceList(int type) Create a new ReferenceList objectCreate a new Transforms objectcreateTransforms(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.private DocumentdecryptElement(Element element) DecryptsEncryptedDatain a single-part operation.private DocumentdecryptElementContent(Element element) decryptKey(EncryptedKey encryptedKey) Decrypt a key from a passed in EncryptedKey structure.decryptKey(EncryptedKey encryptedKey, String algorithm) Decrypt a key from a passed in EncryptedKey structurebyte[]decryptToByteArray(Element element) Decrypt an EncryptedData element to a byte array.Process a DOMDocumentnode.Process a DOMElementnode.Process the contents of a DOMElementnode.encryptData(Document context, String type, InputStream serializedData) Returns anEncryptedDatainterface.encryptData(Document context, Element element) Returns anEncryptedDatainterface.encryptData(Document context, Element element, boolean contentMode) Returns anEncryptedDatainterface.private EncryptedDataencryptData(Document context, Element element, String type, InputStream serializedData) private DocumentencryptElement(Element element) Encrypts anElementand replaces it with its encrypted counterpart in the contextDocument, that is, theDocumentspecified when one callsgetInstance.private DocumentencryptElementContent(Element element) Encrypts aNodeList(the contents of anElement) and replaces its parentElement's content with this the resultingEncryptedTypewithin the contextDocument, that is, theDocumentspecified when one callsgetInstance.encryptKey(Document doc, Key key) Encrypts a key to an EncryptedKey structureencryptKey(Document doc, Key key, String mgfAlgorithm, byte[] oaepParams) Encrypts a key to an EncryptedKey structureencryptKey(Document doc, Key key, String mgfAlgorithm, byte[] oaepParams, SecureRandom random) Encrypts a key to an EncryptedKey structureGet the EncryptedData being builtGet the EncryptedData being build Returns the EncryptedData being built during an ENCRYPT operation.static XMLCipherReturns anXMLCipherthat implements no specific transformation, and can therefore only be used for decrypt or unwrap operations where the encryption method is defined in theEncryptionMethodelement.static XMLCiphergetInstance(String transformation) Returns anXMLCipherthat implements the specified transformation and operates on the specified context document.static XMLCiphergetInstance(String transformation, String canon) Returns anXMLCipherthat 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 XMLCiphergetInstance(String transformation, String canon, String digestMethod) Returns anXMLCipherthat 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 XMLCiphergetProviderInstance(String provider) Returns anXMLCipherthat implements no specific transformation, and can therefore only be used for decrypt or unwrap operations where the encryption method is defined in theEncryptionMethodelement.static XMLCiphergetProviderInstance(String transformation, String provider) Returns anXMLCipherthat implements the specified transformation and operates on the specified context document.static XMLCiphergetProviderInstance(String transformation, String provider, String canon) Returns anXMLCipherthat 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 XMLCiphergetProviderInstance(String transformation, String provider, String canon, String digestMethod) Returns anXMLCipherthat implements the specified transformation, operates on the specified context document and serializes the document with the specified canonicalization algorithm before it encrypts the document.Get the Serializer algorithm to useprivate static booleanvoidInitializes this cipher with a key.private static booleanisValidEncryptionAlgorithm(String algorithm) Checks to ensure that the supplied algorithm is valid.loadEncryptedData(Document context, Element element) Returns anEncryptedDatainterface.loadEncryptedKey(Document context, Element element) Returns anEncryptedKeyinterface.loadEncryptedKey(Element element) Returns anEncryptedKeyinterface.martial(EncryptedData encryptedData) Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriateEncryptedDatamartial(EncryptedKey encryptedKey) Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriateEncryptedKeymartial(ReferenceList referenceList) Martial a ReferenceList Takes a ReferenceList object and returns a DOM Element that represents the appropriateReferenceListmartial(Document context, EncryptedData encryptedData) Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriateEncryptedDatamartial(Document context, EncryptedKey encryptedKey) Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriateEncryptedKeymartial(Document context, ReferenceList referenceList) Martial a ReferenceList Takes a ReferenceList object and returns a DOM Element that represents the appropriateReferenceListvoidregisterInternalKeyResolver(KeyResolverSpi keyResolver) This method is used to add a customKeyResolverSpito an XMLCipher.private static voidremoveContent(Node node) Removes the contents of aNode.voidSet a Key Encryption Key.voidsetSecureValidation(boolean secureValidation) Set whether secure validation is enabled or not.voidsetSerializer(Serializer serializer) Set the Serializer algorithm to useprivate static voidvalidateTransformation(String transformation) Validate the transformation argument of getInstance or getProviderInstance
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
TRIPLEDES
-
AES_128
-
AES_256
-
AES_192
-
AES_128_GCM
-
AES_192_GCM
-
AES_256_GCM
-
SEED_128
-
CAMELLIA_128
-
CAMELLIA_192
-
CAMELLIA_256
-
RSA_v1dot5
-
RSA_OAEP
-
RSA_OAEP_11
-
DIFFIE_HELLMAN
-
TRIPLEDES_KeyWrap
Triple DES EDE (192 bit key) in CBC mode KEYWRAP- See Also:
-
AES_128_KeyWrap
-
AES_256_KeyWrap
-
AES_192_KeyWrap
-
CAMELLIA_128_KeyWrap
-
CAMELLIA_192_KeyWrap
-
CAMELLIA_256_KeyWrap
-
SEED_128_KeyWrap
-
SHA1
-
SHA256
-
SHA512
-
RIPEMD_160
-
XML_DSIG
-
N14C_XML
-
N14C_XML_WITH_COMMENTS
-
EXCL_XML_N14C
-
EXCL_XML_N14C_WITH_COMMENTS
-
PHYSICAL_XML_N14C
N14C_PHYSICAL preserve the physical representation- See Also:
-
BASE64_ENCODING
-
ENCRYPT_MODE
public static final int ENCRYPT_MODEENCRYPT Mode- See Also:
-
DECRYPT_MODE
public static final int DECRYPT_MODEDECRYPT Mode- See Also:
-
UNWRAP_MODE
public static final int UNWRAP_MODEUNWRAP Mode- See Also:
-
WRAP_MODE
public static final int WRAP_MODEWRAP Mode- See Also:
-
ENC_ALGORITHMS
- See Also:
-
HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER
private static final boolean HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER -
contextCipher
Cipher created during initialisation that is used for encryption -
cipherMode
private int cipherModeMode that the XMLCipher object is operating in -
algorithm
URI of algorithm that is being used for cryptographic operation -
requestedJCEProvider
Cryptographic provider requested by caller -
canon
Holds c14n to serialize, if initialized then _always_ use this c14n to serialize -
contextDocument
Used for creation of DOM nodes in WRAP and ENCRYPT modes -
factory
Instance of factory used to create XML Encryption objects -
serializer
Serializer class for going to/from UTF-8 -
key
Local copy of user's key -
kek
Local copy of the kek (used to decrypt EncryptedKeys during a DECRYPT_MODE operation -
ek
-
ed
-
secureValidation
private boolean secureValidation -
digestAlg
-
internalKeyResolvers
List of internal KeyResolvers for DECRYPT and UNWRAP modes.
-
-
Constructor Details
-
XMLCipher
private XMLCipher(String transformation, String provider, String canonAlg, String digestMethod) throws XMLEncryptionException Creates a newXMLCipher.- Parameters:
transformation- the name of the transformation, e.g.,XMLCipher.TRIPLEDES. If null the XMLCipher can only be used for decrypt or unwrap operations where the encryption method is defined in theEncryptionMethodelement.provider- the JCE provider that supplies the transformation, if null use the default provider.canonAlg- the name of the c14n algorithm, ifnulluse standard serializerdigestMethod- An optional digestMethod to use.- Throws:
XMLEncryptionException
-
-
Method Details
-
setSerializer
Set the Serializer algorithm to use -
getSerializer
Get the Serializer algorithm to use -
isValidEncryptionAlgorithm
Checks to ensure that the supplied algorithm is valid.- Parameters:
algorithm- the algorithm to check.- Returns:
- true if the algorithm is valid, otherwise false.
- Since:
- 1.0.
-
validateTransformation
Validate the transformation argument of getInstance or getProviderInstance- Parameters:
transformation- the name of the transformation, e.g.,XMLCipher.TRIPLEDESwhich is shorthand for "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"
-
getInstance
Returns anXMLCipherthat 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 injavax.crypto.Cipher. Instead, it only throws anXMLEncryptionExceptionwhich wraps an underlying exception. The stack trace from the exception should be self explanatory.- Parameters:
transformation- the name of the transformation, e.g.,XMLCipher.TRIPLEDESwhich is shorthand for "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException- See Also:
-
getInstance
public static XMLCipher getInstance(String transformation, String canon) throws XMLEncryptionException Returns anXMLCipherthat implements the specified transformation, operates on the specified context document and serializes the document with the specified canonicalization algorithm before it encrypts the document.- Parameters:
transformation- the name of the transformationcanon- the name of the c14n algorithm, ifnulluse standard serializer- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
getInstance
public static XMLCipher getInstance(String transformation, String canon, String digestMethod) throws XMLEncryptionException Returns anXMLCipherthat implements the specified transformation, operates on the specified context document and serializes the document with the specified canonicalization algorithm before it encrypts the document.- Parameters:
transformation- the name of the transformationcanon- the name of the c14n algorithm, ifnulluse standard serializerdigestMethod- An optional digestMethod to use- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
getProviderInstance
public static XMLCipher getProviderInstance(String transformation, String provider) throws XMLEncryptionException Returns anXMLCipherthat implements the specified transformation and operates on the specified context document.- Parameters:
transformation- the name of the transformationprovider- the JCE provider that supplies the transformation- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
getProviderInstance
public static XMLCipher getProviderInstance(String transformation, String provider, String canon) throws XMLEncryptionException Returns anXMLCipherthat implements the specified transformation, operates on the specified context document and serializes the document with the specified canonicalization algorithm before it encrypts the document.- Parameters:
transformation- the name of the transformationprovider- the JCE provider that supplies the transformationcanon- the name of the c14n algorithm, ifnulluse standard serializer- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
getProviderInstance
public static XMLCipher getProviderInstance(String transformation, String provider, String canon, String digestMethod) throws XMLEncryptionException Returns anXMLCipherthat implements the specified transformation, operates on the specified context document and serializes the document with the specified canonicalization algorithm before it encrypts the document.- Parameters:
transformation- the name of the transformationprovider- the JCE provider that supplies the transformationcanon- the name of the c14n algorithm, ifnulluse standard serializerdigestMethod- An optional digestMethod to use- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
getInstance
Returns anXMLCipherthat implements no specific transformation, and can therefore only be used for decrypt or unwrap operations where the encryption method is defined in theEncryptionMethodelement.- Returns:
- The XMLCipher
- Throws:
XMLEncryptionException
-
getProviderInstance
Returns anXMLCipherthat implements no specific transformation, and can therefore only be used for decrypt or unwrap operations where the encryption method is defined in theEncryptionMethodelement. Allows the caller to specify a provider that will be used for cryptographic operations.- Parameters:
provider- the JCE provider that supplies the transformation- Returns:
- the XMLCipher
- Throws:
XMLEncryptionException
-
init
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. 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()orgetEncryptedKey().- 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:
-
setSecureValidation
public void setSecureValidation(boolean secureValidation) Set whether secure validation is enabled or not. The default is false. -
registerInternalKeyResolver
This method is used to add a customKeyResolverSpito an XMLCipher. These KeyResolvers are used in KeyInfo objects in DECRYPT and UNWRAP modes.- Parameters:
keyResolver-
-
getEncryptedData
Get the EncryptedData being builtReturns the EncryptedData being built during an ENCRYPT operation. This can then be used by applications to add KeyInfo elements and set other parameters.
- Returns:
- The EncryptedData being built
-
getEncryptedKey
Get the EncryptedData being build Returns the EncryptedData being built during an ENCRYPT operation. This can then be used by applications to add KeyInfo elements and set other parameters.- Returns:
- The EncryptedData being built
-
setKEK
Set a Key Encryption Key.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.
- Parameters:
kek- The key to use for de/encrypting key data
-
martial
Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriateEncryptedDataNote: This should only be used in cases where the context document has been passed in via a call to doFinal.
- Parameters:
encryptedData- EncryptedData object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
martial
Martial an EncryptedData Takes an EncryptedData object and returns a DOM Element that represents the appropriateEncryptedData- Parameters:
context- The document that will own the returned nodesencryptedData- EncryptedData object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
martial
Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriateEncryptedKeyNote: This should only be used in cases where the context document has been passed in via a call to doFinal.
- Parameters:
encryptedKey- EncryptedKey object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
martial
Martial an EncryptedKey Takes an EncryptedKey object and returns a DOM Element that represents the appropriateEncryptedKey- Parameters:
context- The document that will own the created nodesencryptedKey- EncryptedKey object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
martial
Martial a ReferenceList Takes a ReferenceList object and returns a DOM Element that represents the appropriateReferenceListNote: This should only be used in cases where the context document has been passed in via a call to doFinal.
- Parameters:
referenceList- ReferenceList object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
martial
Martial a ReferenceList Takes a ReferenceList object and returns a DOM Element that represents the appropriateReferenceList- Parameters:
context- The document that will own the created nodesreferenceList- ReferenceList object to martial- Returns:
- the DOM
Elementrepresenting the passed in object
-
encryptElement
Encrypts anElementand replaces it with its encrypted counterpart in the contextDocument, that is, theDocumentspecified when one callsgetInstance.- Parameters:
element- theElementto encrypt.- Returns:
- the context
Documentwith the encryptedElementhaving replaced the sourceElement. - Throws:
Exception
-
encryptElementContent
Encrypts aNodeList(the contents of anElement) and replaces its parentElement's content with this the resultingEncryptedTypewithin the contextDocument, that is, theDocumentspecified when one callsgetInstance.- Parameters:
element- theNodeListto encrypt.- Returns:
- the context
Documentwith the encryptedNodeListhaving replaced the content of the sourceElement. - Throws:
Exception
-
doFinal
-
doFinal
-
doFinal
Process the contents of a DOMElementnode. The processing depends on the initialization parameters ofinit().- Parameters:
context- the contextDocument.element- theElementwhich contents is to be encrypted.content-- Returns:
- the processed
Document. - Throws:
Exception- to indicate any exceptional conditions.
-
encryptData
Returns anEncryptedDatainterface. Use this operation if you want to have full control over the contents of theEncryptedDatastructure. This does not change the source document in any way.- Parameters:
context- the contextDocument.element- theElementthat will be encrypted.- Returns:
- the
EncryptedData - Throws:
Exception
-
encryptData
public EncryptedData encryptData(Document context, String type, InputStream serializedData) throws Exception Returns anEncryptedDatainterface. 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.- Parameters:
context- the contextDocument.type- a URI identifying type information about the plaintext form of the encrypted content (may benull)serializedData- the serialized data- Returns:
- the
EncryptedData - Throws:
Exception
-
encryptData
public EncryptedData encryptData(Document context, Element element, boolean contentMode) throws Exception Returns anEncryptedDatainterface. Use this operation if you want to have full control over the contents of theEncryptedDatastructure. This does not change the source document in any way.- Parameters:
context- the contextDocument.element- theElementthat will be encrypted.contentMode-trueto encrypt element's content only,falseotherwise- Returns:
- the
EncryptedData - Throws:
Exception
-
encryptData
private EncryptedData encryptData(Document context, Element element, String type, InputStream serializedData) throws Exception - Throws:
Exception
-
constructBlockCipherParameters
Build anAlgorithmParameterSpecinstance used to initialize aCipherinstance for block cipher encryption and decryption.- Parameters:
algorithm- the XML encryption algorithm URIiv- the initialization vector- Returns:
- the newly constructed AlgorithmParameterSpec instance, appropriate for the specified algorithm
-
loadEncryptedData
public EncryptedData loadEncryptedData(Document context, Element element) throws XMLEncryptionException Returns anEncryptedDatainterface. Use this operation if you want to load anEncryptedDatastructure from a DOM structure and manipulate the contents.- Parameters:
context- the contextDocument.element- theElementthat will be loaded- Returns:
- the
EncryptedData - Throws:
XMLEncryptionException
-
loadEncryptedKey
public EncryptedKey loadEncryptedKey(Document context, Element element) throws XMLEncryptionException Returns anEncryptedKeyinterface. Use this operation if you want to load anEncryptedKeystructure from a DOM structure and manipulate the contents.- Parameters:
context- the contextDocument.element- theElementthat will be loaded- Returns:
- the
EncryptedKey - Throws:
XMLEncryptionException
-
loadEncryptedKey
Returns anEncryptedKeyinterface. Use this operation if you want to load anEncryptedKeystructure from a DOM structure and manipulate the contents. Assumes that the context document is the document that owns the element- Parameters:
element- theElementthat will be loaded- Returns:
- the
EncryptedKey - Throws:
XMLEncryptionException
-
encryptKey
Encrypts a key to an EncryptedKey structure- Parameters:
doc- the Context document that will be used to general DOMkey- Key to encrypt (will use previously set KEK to perform encryption- Returns:
- the
EncryptedKey - Throws:
XMLEncryptionException
-
encryptKey
public EncryptedKey encryptKey(Document doc, Key key, String mgfAlgorithm, byte[] oaepParams) throws XMLEncryptionException Encrypts a key to an EncryptedKey structure- Parameters:
doc- the Context document that will be used to general DOMkey- Key to encrypt (will use previously set KEK to perform encryptionmgfAlgorithm- The xenc11 MGF Algorithm to useoaepParams- The OAEPParams to use- Returns:
- the
EncryptedKey - Throws:
XMLEncryptionException
-
encryptKey
public EncryptedKey encryptKey(Document doc, Key key, String mgfAlgorithm, byte[] oaepParams, SecureRandom random) throws XMLEncryptionException Encrypts a key to an EncryptedKey structure- Parameters:
doc- the Context document that will be used to general DOMkey- Key to encrypt (will use previously set KEK to perform encryptionmgfAlgorithm- The xenc11 MGF Algorithm to useoaepParams- The OAEPParams to userandom- The SecureRandom instance to use when initializing the Cipher- Returns:
- the
EncryptedKey - Throws:
XMLEncryptionException
-
decryptKey
Decrypt a key from a passed in EncryptedKey structure- Parameters:
encryptedKey- Previously loaded EncryptedKey that needs to be decrypted.algorithm- Algorithm for the decrypted key- Returns:
- a key corresponding to the given type
- Throws:
XMLEncryptionException
-
constructOAEPParameters
private OAEPParameterSpec constructOAEPParameters(String encryptionAlgorithm, String digestAlgorithm, String mgfAlgorithm, byte[] oaepParams) Construct an OAEPParameterSpec object from the given parameters -
constructCipher
private Cipher constructCipher(String algorithm, String digestAlgorithm) throws XMLEncryptionException Construct a Cipher object- Throws:
XMLEncryptionException
-
constructCipher
private Cipher constructCipher(String algorithm, String digestAlgorithm, Exception nsae) throws XMLEncryptionException - Throws:
XMLEncryptionException
-
decryptKey
Decrypt a key from a passed in EncryptedKey structure. This version is used mainly internally, when the cipher already has an EncryptedData loaded. The algorithm URI will be read from the EncryptedData- Parameters:
encryptedKey- Previously loaded EncryptedKey that needs to be decrypted.- Returns:
- a key corresponding to the given type
- Throws:
XMLEncryptionException
-
removeContent
Removes the contents of aNode.- Parameters:
node- theNodeto clear.
-
decryptElement
DecryptsEncryptedDatain a single-part operation.- Parameters:
element- theEncryptedDatato decrypt.- Returns:
- the
Nodeas a result of the decrypt operation. - Throws:
XMLEncryptionException
-
decryptElementContent
- Parameters:
element-- Returns:
- the
Nodeas a result of the decrypt operation. - Throws:
XMLEncryptionException
-
decryptToByteArray
Decrypt an EncryptedData element to a byte array. When passed in an EncryptedData node, returns the decryption as a byte array. Does not modify the source document.- Parameters:
element-- Returns:
- the bytes resulting from the decryption
- Throws:
XMLEncryptionException
-
createEncryptedData
Creates anEncryptedDataElement. 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
- Parameters:
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 theEncryptedDataor the URI to set in the CipherReference (usage will depend on thetype- Returns:
- the
EncryptedDataElement. - Throws:
XMLEncryptionException
-
createEncryptedKey
Creates anEncryptedKeyElement. 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
- Parameters:
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 theEncryptedKeyor the URI to set in the CipherReference (usage will depend on thetype- Returns:
- the
EncryptedKeyElement. - Throws:
XMLEncryptionException
-
createAgreementMethod
Create an AgreementMethod object- Parameters:
algorithm- Algorithm of the agreement method- Returns:
- a new
AgreementMethod
-
createCipherData
Create a CipherData object- Parameters:
type- Type of this CipherData (either VALUE_TUPE or REFERENCE_TYPE)- Returns:
- a new
CipherData
-
createCipherReference
Create a CipherReference object- Parameters:
uri- The URI that the reference will refer- Returns:
- a new
CipherReference
-
createCipherValue
Create a CipherValue element- Parameters:
value- The value to set the ciphertext to- Returns:
- a new
CipherValue
-
createEncryptionMethod
Create an EncryptionMethod object- Parameters:
algorithm- Algorithm for the encryption- Returns:
- a new
EncryptionMethod
-
createEncryptionProperties
Create an EncryptionProperties element- Returns:
- a new
EncryptionProperties
-
createEncryptionProperty
Create a new EncryptionProperty element- Returns:
- a new
EncryptionProperty
-
createReferenceList
Create a new ReferenceList object- Parameters:
type- ReferenceList.DATA_REFERENCE or ReferenceList.KEY_REFERENCE- Returns:
- a new
ReferenceList
-
createTransforms
Create a new Transforms objectNote: A context document must have been set elsewhere (possibly via a call to doFinal). If not, use the createTransforms(Document) method.
- Returns:
- a new
Transforms
-
createTransforms
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.- Parameters:
doc- Document that will own the created Transforms node- Returns:
- a new
Transforms
-
haveFunctionalIdentityTransformer
private static boolean haveFunctionalIdentityTransformer()
-