com.zipxap.vfs.dal.utility
Class PasswordBasedEncryptionUtility

java.lang.Object
  extended by com.zipxap.vfs.dal.utility.PasswordBasedEncryptionUtility

public class PasswordBasedEncryptionUtility
extends java.lang.Object

This is a utility class to help with password-based encryption. This implementation uses PKCS#5 standard, which specifies that the Data Encryption Standard (DES) algorithm be used, combined with either MD2 (RFC 1422) or MD5 (RFC 1321) hash-code generation.


Constructor Summary
PasswordBasedEncryptionUtility()
           
 
Method Summary
static byte[] decrypt(byte[] cyphertext, java.lang.String password)
          Decrypt the specified cyphertext using the standard salt and nIteration values.
static byte[] decrypt(byte[] cyphertext, java.lang.String password, byte[] salt, int nIterations)
          Decrypt the specified cyphertext using the specified salt and nIteration values.
static byte[] encrypt(byte[] cleartext, java.lang.String password)
          Encrypt the specified cleartext using the standard salt and nIteration values.
static byte[] encrypt(byte[] cleartext, java.lang.String password, byte[] salt, int nIterations)
          Encrypt the specified cleartext using the specified salt and nIteration values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PasswordBasedEncryptionUtility

public PasswordBasedEncryptionUtility()
Method Detail

encrypt

public static byte[] encrypt(byte[] cleartext,
                             java.lang.String password)
Encrypt the specified cleartext using the standard salt and nIteration values.

Parameters:
cleartext - The text to be encrypted.
password - The password to use to encrypt the cleartext.
Returns:
the encrypted version of the specified cleartext

encrypt

public static byte[] encrypt(byte[] cleartext,
                             java.lang.String password,
                             byte[] salt,
                             int nIterations)
Encrypt the specified cleartext using the specified salt and nIteration values.

Parameters:
cleartext - The text to be encrypted.
password - The password to use to encrypt the cleartext.
salt - A byte[] that gets appended to the password.
nIterations - The number of times to apply the encryption.
Returns:
the encrypted version of the specified cleartext

decrypt

public static byte[] decrypt(byte[] cyphertext,
                             java.lang.String password)
Decrypt the specified cyphertext using the standard salt and nIteration values.

Parameters:
cyphertext - The text to be decrypted.
password - The password to use to decrypted the cyphertext.
Returns:
the decrypted cyphertext, else an empty byte array if the given cyphertext and password combination caused an Exception.

decrypt

public static byte[] decrypt(byte[] cyphertext,
                             java.lang.String password,
                             byte[] salt,
                             int nIterations)
Decrypt the specified cyphertext using the specified salt and nIteration values.

Parameters:
cyphertext - The text to be decrypted.
password - The password to use to decrypted the cyphertext.
salt - A byte[] that gets appended to the password.
nIterations - The number of times to apply the decryption.
Returns:
the decrypted cyphertext, else an empty byte array if the given cyphertext and password combination caused an Exception.