org.jboss.identity.federation.api.util
Class XMLEncryptionUtil

java.lang.Object
  extended by org.jboss.identity.federation.api.util.XMLEncryptionUtil

public class XMLEncryptionUtil
extends java.lang.Object

XML Encryption Util Note: This utility is currently using Apache XML Security library API. JSR-106 is not yet final. Until that happens,we rely on the non-standard API.

Since:
Feb 4, 2009
Author:
Anil.Saldhana@redhat.com

Field Summary
static java.lang.String CIPHER_DATA_LOCALNAME
           
static java.lang.String DS_KEY_INFO
           
static java.lang.String ENCRYPTED_KEY_LOCALNAME
           
static java.lang.String XMLENC_NS
           
static java.lang.String XMLNS
           
static java.lang.String XMLSIG_NS
           
 
Constructor Summary
XMLEncryptionUtil()
           
 
Method Summary
static org.w3c.dom.Element decryptElementInDocument(org.w3c.dom.Document documentWithEncryptedElement, java.security.PrivateKey privateKey)
          Decrypt an encrypted element inside a document
static void encryptElement(javax.xml.namespace.QName elementQName, org.w3c.dom.Document document, java.security.PublicKey publicKey, javax.crypto.SecretKey secretKey, int keySize, javax.xml.namespace.QName wrappingElementQName, boolean addEncryptedKeyInKeyInfo)
          Given an element in a Document, encrypt the element and replace the element in the document with the encrypted data
static org.w3c.dom.Element encryptElementInDocument(org.w3c.dom.Document document, java.security.PublicKey publicKey, javax.crypto.SecretKey secretKey, int keySize, javax.xml.namespace.QName wrappingElementQName, boolean addEncryptedKeyInKeyInfo)
          Encrypt the root document element inside a Document.
static org.apache.xml.security.encryption.EncryptedKey encryptKey(org.w3c.dom.Document document, javax.crypto.SecretKey keyToBeEncrypted, java.security.PublicKey keyUsedToEncryptSecretKey, int keySize)
           Encrypt the Key to be transported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CIPHER_DATA_LOCALNAME

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

ENCRYPTED_KEY_LOCALNAME

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

DS_KEY_INFO

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

XMLNS

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

XMLSIG_NS

public static java.lang.String XMLSIG_NS

XMLENC_NS

public static java.lang.String XMLENC_NS
Constructor Detail

XMLEncryptionUtil

public XMLEncryptionUtil()
Method Detail

encryptKey

public static org.apache.xml.security.encryption.EncryptedKey encryptKey(org.w3c.dom.Document document,
                                                                         javax.crypto.SecretKey keyToBeEncrypted,
                                                                         java.security.PublicKey keyUsedToEncryptSecretKey,
                                                                         int keySize)
                                                                  throws java.lang.Exception

Encrypt the Key to be transported

Data is encrypted with a SecretKey. Then the key needs to be transported to the other end where it is needed for decryption. For the Key transport, the SecretKey is encrypted with the recipient's public key. At the receiving end, the receiver can decrypt the Secret Key using his private key.s

Parameters:
document -
keyToBeEncrypted - Symmetric Key (SecretKey)
keyUsedToEncryptSecretKey - Asymmetric Key (Public Key)
keySize - Length of the key
Returns:
Throws:
java.lang.Exception

encryptElement

public static void encryptElement(javax.xml.namespace.QName elementQName,
                                  org.w3c.dom.Document document,
                                  java.security.PublicKey publicKey,
                                  javax.crypto.SecretKey secretKey,
                                  int keySize,
                                  javax.xml.namespace.QName wrappingElementQName,
                                  boolean addEncryptedKeyInKeyInfo)
                           throws java.lang.Exception
Given an element in a Document, encrypt the element and replace the element in the document with the encrypted data

Parameters:
elementQName - QName of the element that we like to encrypt
publicKey -
secretKey -
keySize -
wrappingElementQName - A QName of an element that will wrap the encrypted element
addEncryptedKeyInKeyInfo - Need for the EncryptedKey to be placed in ds:KeyInfo
Throws:
java.lang.Exception

encryptElementInDocument

public static org.w3c.dom.Element encryptElementInDocument(org.w3c.dom.Document document,
                                                           java.security.PublicKey publicKey,
                                                           javax.crypto.SecretKey secretKey,
                                                           int keySize,
                                                           javax.xml.namespace.QName wrappingElementQName,
                                                           boolean addEncryptedKeyInKeyInfo)
                                                    throws java.lang.Exception
Encrypt the root document element inside a Document. NOTE: The document root element will be replaced by the wrapping element.

Parameters:
document - Document that contains an element to encrypt
publicKey - The Public Key used to encrypt the secret encryption key
secretKey - The secret encryption key
keySize - Length of key
wrappingElementQName - QName of the element to be used to wrap around the cipher data.
addEncryptedKeyInKeyInfo - Should the encrypted key be inside a KeyInfo or added as a peer of Cipher Data
Returns:
An element that has the wrappingElementQName
Throws:
java.lang.Exception

decryptElementInDocument

public static org.w3c.dom.Element decryptElementInDocument(org.w3c.dom.Document documentWithEncryptedElement,
                                                           java.security.PrivateKey privateKey)
                                                    throws java.lang.Exception
Decrypt an encrypted element inside a document

Parameters:
documentWithEncryptedElement -
privateKey - key need to unwrap the encryption key
Returns:
the document with the encrypted element replaced by the data element
Throws:
java.lang.Exception


Copyright © 2009 JBoss Inc.. All Rights Reserved.