ewe.security
Class Decryptor

java.lang.Object
  extended byewe.security.Encryptor
      extended byewe.security.Decryptor
All Implemented Interfaces:
DataProcessor

public class Decryptor
extends Encryptor

A Decryptor implements the Blowfish CBC algorithm to decrypt data as encrypted by an Encryptor. You can use it in two ways:

You can use it as a straight ewe.io.DataProcessor where you provide it with encrypted data bytes and then receive the decrypted plain text. However with this method the data must be padded up to a size that is a multiple of 8 bytes which is the minimum block size of the Decryptor.

You can also use the more powerful decrypt() methods if the data was encrypted by an Encryptor using the encrypt() method. This method adds more advanced capabilities to the encryption, including "salting" the data (adding some randomness to it), optionally compressing the data and optionally signing the data with a private key. All these add to the security of the encrypted data and will also take care of stripping any padding from the encrypted data, thereby ensuring that the decrypted data is the exact length of the original plain text.


Field Summary
 
Fields inherited from class ewe.security.Encryptor
digest, ENCRYPT_WITHOUT_COMPRESSION, isDecryptor
 
Constructor Summary
Decryptor(byte[] key)
          Create a Decryptor using the specified key.
Decryptor(String key)
          Create a Decryptor using the specified key.
 
Method Summary
 byte[] decrypt(byte[] encryptedData, int offset, int length)
          Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this Decryptor object as the decryptor.
 ByteArray decrypt(ByteArray dest, byte[] encryptedData, int offset, int length, Signature signature)
          Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this Decryptor object as the decryptor.
static ByteArray decrypt(DataProcessor processor, ByteArray dest, byte[] encryptedData, int offset, int length, Signature signature)
          Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this any DataProcessor object as the decryptor.
 
Methods inherited from class ewe.security.Encryptor
closeProcess, encrypt, encrypt, encrypt, encrypt, getBlockSize, getMaxBlockSize, makeEncryptorTest, processBlock, reset, stringToKey, testDecryptor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

Decryptor

public Decryptor(String key)
Create a Decryptor using the specified key. This method uses an SHA1 object to create a 160-bit hash of the password and this is then used as the key to the BlowfishCBC algorithm.

Parameters:
key - a password key.

Decryptor

public Decryptor(byte[] key)
Create a Decryptor using the specified key.

Parameters:
key - a key which is a sequence of bytes up to a maximum of MAXKEYLENGTH (448 bits)
Method Detail

decrypt

public byte[] decrypt(byte[] encryptedData,
                      int offset,
                      int length)
               throws StreamCorruptedException
Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this Decryptor object as the decryptor.

Parameters:
encryptedData - the encrypted data.
offset - the start of the encrypted data bytes.
length - the number of data bytes.
Returns:
the decrypted bytes.
Throws:
StreamCorruptedException - if there was an error with the data or if the decryptor is incorrect.

decrypt

public ByteArray decrypt(ByteArray dest,
                         byte[] encryptedData,
                         int offset,
                         int length,
                         Signature signature)
                  throws StreamCorruptedException
Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this Decryptor object as the decryptor.

Parameters:
dest - an optional destination ByteArray to hold the decrypted data.
encryptedData - the encrypted data.
offset - the start of the encrypted data bytes.
length - the number of data bytes.
signature - an optional Signature object setup with the received or stored signature of the data as produced by the encrypt() process. If it is not null the Signature will be used to validate the decrypted data.
Returns:
the decrypted bytes in the destination ByteArray or a new one if dest is null.
Throws:
StreamCorruptedException - if there was an error with the data or if the decryptor is incorrect.

decrypt

public static ByteArray decrypt(DataProcessor processor,
                                ByteArray dest,
                                byte[] encryptedData,
                                int offset,
                                int length,
                                Signature signature)
                         throws StreamCorruptedException
Decrypt data that has been encrypted by an Encrytpor with an encrypt() method using this any DataProcessor object as the decryptor. This method is called by the other two decrypt() methods using this Decryptor object as the DataProcessor object.

Parameters:
processor - a DataProcessor object to decrypt the data.
dest - an optional destination ByteArray to hold the decrypted data.
encryptedData - the encrypted data.
offset - the start of the encrypted data bytes.
length - the number of data bytes.
signature - an optional Signature object setup with the received or stored signature of the data as produced by the encrypt() process. If it is not null the Signature will be used to validate the decrypted data.
Returns:
the decrypted bytes in the destination ByteArray or a new one if dest is null.
Throws:
StreamCorruptedException - if there was an error with the data or if the decryptor is incorrect.