ewe.security
Class BlowfishECB

java.lang.Object
  extended byewe.security.BlowfishECB
Direct Known Subclasses:
BlowfishCBC

public class BlowfishECB
extends Object

Implementation of the Blowfish encryption algorithm in ECB mode.


Field Summary
static int BLOCKSIZE
          block size of this cipher (in bytes)
static int MAXKEYLENGTH
          maximum possible key length in bytes
 
Constructor Summary
BlowfishECB(byte[] key)
          The default constructor, using a simple binary key.
BlowfishECB(byte[] key, int nOfs, int nLen)
           
 
Method Summary
static int byteArrayToInt(byte[] buf, int nOfs)
           
 void cleanUp()
          To clear data in the boxes before an instance is freed, the actual value of this call can be argued, yet still nice to have it.
 int decrypt(byte[] inBuf, int nInPos, byte[] outBuf, int nOutPos, int nLen)
          Decrypts a byte buffer to another buffer, extra misaligned data will not be processed.
 int encrypt(byte[] inBuf, int nInPos, byte[] outBuf, int nOutPos, int nLen)
          Encrypts a byte buffer to another buffer, extra misaligned data will not be processed.
protected  int encryptPrv(byte[] inBuf, int nInPos, byte[] outBuf, int nOutPos, int nLen)
           
 void initialize(byte[] key, int nOfs, int nLen)
          Initializes the instances, but does not really reset it since the PBOXes are not reset.
 void reset()
          Reset the Encryptor/Decryptor using the last key used to initialize it.
 void reset(byte[] key, int nOfs, int nlen)
          Reset the Encryptor/Decryptor using a specific key.
 boolean weakKeyCheck()
          To check if an instance actually was using a weak key, if so it might be better to use a different key or salt the existing one as alternative.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

MAXKEYLENGTH

public static final int MAXKEYLENGTH
maximum possible key length in bytes

See Also:
Constant Field Values

BLOCKSIZE

public static final int BLOCKSIZE
block size of this cipher (in bytes)

See Also:
Constant Field Values
Constructor Detail

BlowfishECB

public BlowfishECB(byte[] key)
The default constructor, using a simple binary key.

Parameters:
key - key material, up to MAXKEYLENGTH bytes

BlowfishECB

public BlowfishECB(byte[] key,
                   int nOfs,
                   int nLen)
See Also:
BlowfishJ.BlowfishECB#initialize(byte[], int, int)
Method Detail

reset

public void reset()
Reset the Encryptor/Decryptor using the last key used to initialize it.


reset

public void reset(byte[] key,
                  int nOfs,
                  int nlen)
Reset the Encryptor/Decryptor using a specific key.


byteArrayToInt

public static final int byteArrayToInt(byte[] buf,
                                       int nOfs)

initialize

public void initialize(byte[] key,
                       int nOfs,
                       int nLen)
Initializes the instances, but does not really reset it since the PBOXes are not reset. Use the reset() methods to reset it.

Parameters:
key - key material, up to MAXKEYLENGTH bytes
nOfs - where to start reading
nLen - number of bytes

cleanUp

public void cleanUp()
To clear data in the boxes before an instance is freed, the actual value of this call can be argued, yet still nice to have it.


weakKeyCheck

public boolean weakKeyCheck()
To check if an instance actually was using a weak key, if so it might be better to use a different key or salt the existing one as alternative.

Returns:
true: weak key detected / false: key is fine

encryptPrv

protected int encryptPrv(byte[] inBuf,
                         int nInPos,
                         byte[] outBuf,
                         int nOutPos,
                         int nLen)

encrypt

public int encrypt(byte[] inBuf,
                   int nInPos,
                   byte[] outBuf,
                   int nOutPos,
                   int nLen)
Encrypts a byte buffer to another buffer, extra misaligned data will not be processed.

Parameters:
inBuf - buffer with plaintext data
nInPos - where to start reading the plaintext data
outBuf - buffer to put the ciphertext data
nOutPos - where to start writing the ciphertext data
nLen - number of bytes to encrypt
Returns:
number of bytes to encrypted

decrypt

public int decrypt(byte[] inBuf,
                   int nInPos,
                   byte[] outBuf,
                   int nOutPos,
                   int nLen)
Decrypts a byte buffer to another buffer, extra misaligned data will not be processed.

Parameters:
inBuf - buffer with ciphertext data
nInPos - where to start reading the ciphertext data
outBuf - buffer to put the plaintext data
nOutPos - where to start writing the plaintext data
nLen - number of bytes to decrypt
Returns:
number of bytes to encrypted