anon.crypto
Class XMLEncryption

java.lang.Object
  extended by anon.crypto.XMLEncryption

public final class XMLEncryption
extends java.lang.Object


Field Summary
private static int MIN_ITERATIONS
           
private static int SALT_SIZE
           
static java.lang.String XML_ELEMENT_NAME
           
 
Constructor Summary
private XMLEncryption()
           
 
Method Summary
private static byte[] codeDataCBCwithHMAC(boolean encrypt, byte[] barInput, org.bouncycastle.crypto.CipherParameters encKey, org.bouncycastle.crypto.CipherParameters macKey)
          The part that is the same for encryption and decryption..
private static byte[] codeDataCTS(boolean encrypt, byte[] barInput, org.bouncycastle.crypto.CipherParameters params)
          The part that is the same for encryption and decryption..
static org.w3c.dom.Element decryptElement(org.w3c.dom.Element elemCrypt, IMiscPasswordReader a_passwordReader)
           
static org.w3c.dom.Element decryptElement(org.w3c.dom.Element elemCrypt, java.lang.String password)
          Decrypts an XML element
static boolean encryptElement(org.w3c.dom.Element elemPlain, MyRSAPublicKey publicKey)
          Encrypts an Element using a public key.
static org.w3c.dom.Element encryptElement(org.w3c.dom.Element elemPlain, java.lang.String password)
          Encrypts an element and all its children using PKCS#12 and the given password.
private static org.bouncycastle.crypto.CipherParameters generatePBEKey(java.lang.String password, byte[] kSalt)
          Generates a key from a password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_ELEMENT_NAME

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

SALT_SIZE

private static final int SALT_SIZE
See Also:
Constant Field Values

MIN_ITERATIONS

private static final int MIN_ITERATIONS
See Also:
Constant Field Values
Constructor Detail

XMLEncryption

private XMLEncryption()
Method Detail

encryptElement

public static org.w3c.dom.Element encryptElement(org.w3c.dom.Element elemPlain,
                                                 java.lang.String password)
                                          throws java.lang.Exception
Encrypts an element and all its children using PKCS#12 and the given password. The encrypted Element replaces the plaintext Element inside its OwnerDocument. Note: The document Element cannot be encrypted using this function. For information on the XML encryption standard see also http://www.w3.org/TR/xmlenc-core/

Parameters:
elemPlain - Element to be encrypted (not the DocumentElement!)
password - String a password
Returns:
Element a pointer to the encrypted element
Throws:
java.lang.Exception

generatePBEKey

private static org.bouncycastle.crypto.CipherParameters generatePBEKey(java.lang.String password,
                                                                       byte[] kSalt)
Generates a key from a password.

Parameters:
password - String password
kSalt - byte[] random salt
Returns:
the Key with IV

codeDataCTS

private static byte[] codeDataCTS(boolean encrypt,
                                  byte[] barInput,
                                  org.bouncycastle.crypto.CipherParameters params)
                           throws java.lang.Exception
The part that is the same for encryption and decryption..

Parameters:
encrypt - boolean true=encrypt, false=decrypt
barInput - byte[] input plain or ciphertext
params - the key
Returns:
byte[]
Throws:
java.lang.Exception

codeDataCBCwithHMAC

private static byte[] codeDataCBCwithHMAC(boolean encrypt,
                                          byte[] barInput,
                                          org.bouncycastle.crypto.CipherParameters encKey,
                                          org.bouncycastle.crypto.CipherParameters macKey)
                                   throws java.lang.Exception
The part that is the same for encryption and decryption..

Parameters:
encrypt - boolean true=encrypt, false=decrypt
barInput - byte[] input plain or ciphertext
params - the key
Returns:
byte[]
Throws:
java.lang.Exception

decryptElement

public static org.w3c.dom.Element decryptElement(org.w3c.dom.Element elemCrypt,
                                                 java.lang.String password)
                                          throws java.lang.Exception
Decrypts an XML element

Parameters:
elemCrypt - Element
password - String
Returns:
Element
Throws:
java.lang.Exception

decryptElement

public static org.w3c.dom.Element decryptElement(org.w3c.dom.Element elemCrypt,
                                                 IMiscPasswordReader a_passwordReader)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

encryptElement

public static boolean encryptElement(org.w3c.dom.Element elemPlain,
                                     MyRSAPublicKey publicKey)
Encrypts an Element using a public key. The element and all of its content is replaced by the encryption. The resulting encrypted xml struct is as follows: ... ...