j_waste.crypto
Class Blowfish

java.lang.Object
  extended byj_waste.crypto.Blowfish

public class Blowfish
extends java.lang.Object

This class handles the Blowfish encryption and decryption.

Version:
0.1
Author:
Fredrik Hultin (frehul@users.sourceforge.net), Mattias Ek (matek@users.sourceforge.net)

Constructor Summary
Blowfish(byte[] sessionKey, byte[] ivEnc, byte[] ivDec, java.lang.String mode)
          Constructs a new Blowfish object.
 
Method Summary
 byte[] decrypt(byte[] input)
          This method decrypts the specified array with the initialized session key and iv.
 byte[] decryptWPCBC(byte[] input)
          This method decryts the input array the same way as the PCBC decryption in waste.
 byte[] encrypt(byte[] input)
          This method encrypts the specified array with the initialized session key and iv.
 byte[] encryptWPCBC(byte[] input)
          This method encryts the input array the same way as the PCBC encryption in waste.
 byte[] generateKey(int keySize)
          This method generates a key with the specified key size.
static void main(java.lang.String[] argv)
          This method will pad out the input array to a multiple of the Blowfish block size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Blowfish

public Blowfish(byte[] sessionKey,
                byte[] ivEnc,
                byte[] ivDec,
                java.lang.String mode)
Constructs a new Blowfish object.

Parameters:
sessionKey - The session key to be used.
ivEnc - The initialization vector for encryption.
ivDec - The initialization vector for decryption.
mode - The mode of encryption. (i.e. CBC, PCBC, ECB, WPCBC (WPCBC is compatible with the errorenous PCBC mode in waste.))
Method Detail

encrypt

public byte[] encrypt(byte[] input)
               throws javax.crypto.IllegalBlockSizeException,
                      javax.crypto.BadPaddingException
This method encrypts the specified array with the initialized session key and iv.

Parameters:
input - The input array that will be encrypted.
Returns:
Returns the encrypted array.
Throws:
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

decrypt

public byte[] decrypt(byte[] input)
               throws javax.crypto.IllegalBlockSizeException,
                      javax.crypto.BadPaddingException
This method decrypts the specified array with the initialized session key and iv.

Parameters:
input - The input array that will be decrypted.
Returns:
Returns the decrypted array.
Throws:
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

generateKey

public byte[] generateKey(int keySize)
This method generates a key with the specified key size.

Parameters:
keySize - The size of the key to be generated.
Returns:
Returns the generated key.

encryptWPCBC

public byte[] encryptWPCBC(byte[] input)
This method encryts the input array the same way as the PCBC encryption in waste. This is however not the way PCBC is usually implemented.

Parameters:
input - the data to be encrypted. Must me a multiple of 8 bytes.

decryptWPCBC

public byte[] decryptWPCBC(byte[] input)
This method decryts the input array the same way as the PCBC decryption in waste. This is however not the way PCBC is usually implemented.

Parameters:
input - the data to be encrypted. Must me a multiple of 8 bytes.

main

public static void main(java.lang.String[] argv)
This method will pad out the input array to a multiple of the Blowfish block size.