com.jfw.util
Class Encryption

java.lang.Object
  extended by com.jfw.util.Encryption

public final class Encryption
extends java.lang.Object

You can use this class for encrypt and decrypt data.


Field Summary
static int TO_DECRYPT
          Used in the constructor to set the object in decryption mode.
static int TO_ENCRYPT
          Used in the constructor to set the object in encryption mode.
 
Constructor Summary
Encryption(java.lang.String key4Encryption, int type)
          Create a new object.
Encryption(java.lang.String key4Encryption, int type, java.lang.String encType)
          Create a new object.
 
Method Summary
 byte[] get(byte[] source)
          Encrypt or decrypt an array of bytes.
 javax.crypto.CipherInputStream getInputStream(java.io.InputStream in)
          Returning an encrypted input stream.
 javax.crypto.CipherOutputStream getOutputStream(java.io.OutputStream out)
          Returning an encrypted output stream.
 int getType()
          The mode (encryption or decryption) set in constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO_ENCRYPT

public static final int TO_ENCRYPT
Used in the constructor to set the object in encryption mode.

See Also:
Constant Field Values

TO_DECRYPT

public static final int TO_DECRYPT
Used in the constructor to set the object in decryption mode.

See Also:
Constant Field Values
Constructor Detail

Encryption

public Encryption(java.lang.String key4Encryption,
                  int type,
                  java.lang.String encType)
           throws JFWGenericException
Create a new object.

Parameters:
key4Encryption - the encryption key to use. Must be an ASCII string. You can use the method Secure.encode(java.lang.String) to create an ASCII string.
type - possible values are TO_ENCRYPT or TO_DECRYPT.
encType - the encryption algorithm to use.
Throws:
JFWGenericException

Encryption

public Encryption(java.lang.String key4Encryption,
                  int type)
           throws JFWGenericException
Create a new object. The encryption algorithm is PBEWithMD5AndDES.

Parameters:
key4Encryption - the encryption key to use. Must be an ASCII string. You can use the method Secure.encode(java.lang.String) to create an ASCII string.
type - possible values are TO_ENCRYPT or TO_DECRYPT.
Throws:
JFWGenericException
Method Detail

get

public byte[] get(byte[] source)
           throws JFWGenericException
Encrypt or decrypt an array of bytes. The mode (encryption or decryption) depends on the value of parameter type set in the constructor.

Throws:
JFWGenericException

getType

public int getType()
The mode (encryption or decryption) set in constructor.

Returns:
the attribute type.

getOutputStream

public javax.crypto.CipherOutputStream getOutputStream(java.io.OutputStream out)
Returning an encrypted output stream. There is only one object of encrypted stream per instance.

Parameters:
out - the output stream to use for create the encrypted stream.
Returns:
an encrypted output stream.

getInputStream

public javax.crypto.CipherInputStream getInputStream(java.io.InputStream in)
Returning an encrypted input stream. There is only one object of encrypted stream per instance.

Parameters:
in - the input stream to use for create the encrypted stream.
Returns:
an encrypted input stream.