de.bb.security
Class BlockCipher

java.lang.Object
  |
  +--de.bb.security.BlockCipher
Direct Known Subclasses:
DES, RC2, RC5

public abstract class BlockCipher
extends java.lang.Object


Field Summary
protected  int blockSize
           
 
Constructor Summary
BlockCipher(int _blockSize)
          Creates a new BlockCipher object.
 
Method Summary
 int blockSize()
          Query the used block size.
abstract  void decrypt(byte[] cipherText, int cipherOff, byte[] clearText, int clearOff)
          Decrypt one block of bytes.
 void decryptCBC(byte[] iv, byte[] cipherText, byte[] clearText)
          Decrypt a complete byte array wihthout padding in CBC mode.
 byte[] decryptCBCAndPadd(byte[] iv, byte[] cipherText)
          Decrypt a complete byte array wiht padding in CBC mode.
 void decryptECB(byte[] cipherText, byte[] clearText)
          Decrypt a complete byte array without padding in ECB mode.
abstract  void encrypt(byte[] clearText, int clearOff, byte[] cipherText, int cipherOff)
          Encrypt one block of bytes.
 void encryptCBC(byte[] iv, byte[] clearText, byte[] cipherText)
          Encrypt a complete byte array without padding in CBC mode.
 byte[] encryptCBCAndPadd(byte[] iv, byte[] clearText)
          Encrypt a complete byte array wiht padding in CBC mode.
 void encryptECB(byte[] clearText, byte[] cipherText)
          Encrypt a complete byte array without padding in ECB mode.
protected  int getBufferLength(int plaintextLength)
          Calculate the buffer length for padding
abstract  void setKey(byte[] keyData)
          Set a givem key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockSize

protected int blockSize
Constructor Detail

BlockCipher

public BlockCipher(int _blockSize)
Creates a new BlockCipher object. Derived Objects must pass its block size.
Parameters:
_blockSize - defines the size of the smalles encryptable block
Method Detail

blockSize

public final int blockSize()
Query the used block size.
Returns:
the cipers blocksize

setKey

public abstract void setKey(byte[] keyData)
Set a givem key.
Parameters:
keyData - the bytes which are used for the key

encrypt

public abstract void encrypt(byte[] clearText,
                             int clearOff,
                             byte[] cipherText,
                             int cipherOff)
Encrypt one block of bytes. You may use one byte array as input data and output data, to encrypt in place.
Parameters:
clearText - input data which is encrypted
clearOff - offset into input data
cipherText - output data which is encrypted.
cipherOff - offset into output data

decrypt

public abstract void decrypt(byte[] cipherText,
                             int cipherOff,
                             byte[] clearText,
                             int clearOff)
Decrypt one block of bytes. You may use one byte array as input data and output data, to decrypt in place.
Parameters:
cipherText - output data which is encrypted.
cipherOff - offset into output data
clearText - input data which is encrypted
clearOff - offset into input data

encryptECB

public final void encryptECB(byte[] clearText,
                             byte[] cipherText)
Encrypt a complete byte array without padding in ECB mode. The size must be a multiple of block size. You may use one byte array as input data and output data, to encrypt in place.
Parameters:
clearText - input data which is encrypted
cipherText - output data which is encrypted.

decryptECB

public final void decryptECB(byte[] cipherText,
                             byte[] clearText)
Decrypt a complete byte array without padding in ECB mode. The size must be a multiple of block size. You may use one byte array as input data and output data, to decrypt in place.
Parameters:
cipherText - output data which is encrypted.
clearText - input data which is encrypted

encryptCBC

public final void encryptCBC(byte[] iv,
                             byte[] clearText,
                             byte[] cipherText)
Encrypt a complete byte array without padding in CBC mode. The size must be a multiple of block size. You may use one byte array as input data and output data, to encrypt in place. The initialization vector is updated by this function!
Parameters:
iv - the initialization vector.
clearText - input data which is encrypted
cipherText - output data which is encrypted.

decryptCBC

public final void decryptCBC(byte[] iv,
                             byte[] cipherText,
                             byte[] clearText)
Decrypt a complete byte array wihthout padding in CBC mode. The size must be a multiple of block size. You may use one byte array as input data and output data, to decrypt in place. The initialization vector is updated by this function!
Parameters:
iv - the initialization vector.
cipherText - output data which is encrypted.
clearText - input data which is encrypted

getBufferLength

protected int getBufferLength(int plaintextLength)
Calculate the buffer length for padding
Parameters:
plaintextLength - length of input data
Returns:
plaintextLength + pad length

encryptCBCAndPadd

public final byte[] encryptCBCAndPadd(byte[] iv,
                                      byte[] clearText)
Encrypt a complete byte array wiht padding in CBC mode. The initialization vector is updated by this function!
Parameters:
iv - the initialization vector.
clearText - input data which is encrypted
Returns:
a new allocated array of bytes containing the encrypted data.

decryptCBCAndPadd

public final byte[] decryptCBCAndPadd(byte[] iv,
                                      byte[] cipherText)
Decrypt a complete byte array wiht padding in CBC mode. The initialization vector is updated by this function!
Parameters:
iv - the initialization vector.
cipherText - output data which is encrypted.
Returns:
a new allocated array of bytes containing the encrypted data.