org.bibalex.daf.handlers.cryptography
Class Cryptography

java.lang.Object
  extended by org.bibalex.daf.handlers.cryptography.Cryptography

public class Cryptography
extends java.lang.Object

This class provides a wrapping for the Encryption and Decryption functionalities.

Author:
Ramy.Nagah Currently it only supports one embededd encrption algorithm "PBEWithMD5AndDES", but it can be modified to support multi encrption algoritms or added providers.

Field Summary
private  javax.crypto.Cipher c
          The Ciphering instance used in encryption and decryption
private static char[] hexChar
          The hexadecimal characters in an array to be used in converions from string to hexadecimals, and in validations.
private  javax.crypto.SecretKey key
          The SecretKey instance used in encryption and decryption (generated) from the password and the SALT
private  javax.crypto.spec.PBEParameterSpec paramSpec
           
 
Constructor Summary
Cryptography(java.lang.String strPassword, java.lang.String strSalt)
          Constructor.
 
Method Summary
 java.lang.String Decrypt(java.lang.String strValue)
          Decrypts the given strValue using the instantiated object of Password and Salt
 java.lang.String Encrypt(java.lang.String strValue)
          Encrypts the given strValue using the instantiated object of Password and Salt
protected static byte[] toBinArray(java.lang.String hexStr)
          Converts a Hexadecimal String into a binary array.
static java.lang.String toHexString(byte[] b)
          Converts a String to its equivalent Hexadecimal representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexChar

private static final char[] hexChar
The hexadecimal characters in an array to be used in converions from string to hexadecimals, and in validations.


c

private javax.crypto.Cipher c
The Ciphering instance used in encryption and decryption


key

private javax.crypto.SecretKey key
The SecretKey instance used in encryption and decryption (generated) from the password and the SALT


paramSpec

private javax.crypto.spec.PBEParameterSpec paramSpec
Constructor Detail

Cryptography

public Cryptography(java.lang.String strPassword,
                    java.lang.String strSalt)
             throws java.lang.Exception
Constructor. This class has to be initialized to be able to either Encrypt or Decrypt.

Parameters:
strPassword - Password used in creating the SecretKey.
strSalt - the Salt used in in creating the SecretKey.
Throws:
java.lang.Exception
Method Detail

Encrypt

public java.lang.String Encrypt(java.lang.String strValue)
                         throws java.lang.Exception
Encrypts the given strValue using the instantiated object of Password and Salt

Parameters:
strValue - the value to Encrypt
Returns:
the encrpted String
Throws:
java.lang.Exception

Decrypt

public java.lang.String Decrypt(java.lang.String strValue)
                         throws java.lang.Exception
Decrypts the given strValue using the instantiated object of Password and Salt

Parameters:
strValue - the value to Decrypt
Returns:
the decrpted String
Throws:
java.lang.Exception

toHexString

public static java.lang.String toHexString(byte[] b)
Converts a String to its equivalent Hexadecimal representation.

Parameters:
b - the byte[] to be converted into Hexadecimal String
Returns:
The Hexadecimal representation.

toBinArray

protected static byte[] toBinArray(java.lang.String hexStr)
Converts a Hexadecimal String into a binary array.

Parameters:
hexStr - The Hexadecimal String to be converted.
Returns:
a byte[] representing the binary array.