is.logi.crypto.keys
Class BlowfishKey

java.lang.Object
  |
  +--is.logi.crypto.Crypto
        |
        +--is.logi.crypto.keys.K
              |
              +--is.logi.crypto.keys.SymmetricKey
                    |
                    +--is.logi.crypto.keys.BlowfishKey

public class BlowfishKey
extends SymmetricKey
implements CipherKey

This is the class for Blowfish keys. It is a feistel blockcipher with a 64-bit block size and variable key-size. It was designed by Bruce Schneier and is in the public domain. (This implementation is licensed in the same way as the rest of the logi.crypto package.)

The CDS for a Blowfish key is BlowfishKey(key) with key a string of hexadecimal digits to create a specific key or BlowfishKey(?) for a random BlowfishKey object.

Author:
Logi Ragnarsson (logir@hi.is)

Fields inherited from class is.logi.crypto.Crypto
BIT, cdsPath, keySource, NIBBLE, primeCertainty, random
 
Constructor Summary
BlowfishKey()
          Create a new random 128 bit Blowfish key.
BlowfishKey(byte[] key)
          Create a new Blowfish key with the key bits from key.
BlowfishKey(int n)
          Create a new random n-bit Blowfish key.
 
Method Summary
 int cipherBlockSize()
          The block-size for the Blowfish cipher is 8 bytes.
 void decrypt(byte[] source, int i, byte[] dest, int j)
          Decrypt one block of data.
 void encrypt(byte[] source, int i, byte[] dest, int j)
          Encrypt one block of data.
 boolean equals(java.lang.Object o)
          Return true iff the two keys are equivalent.
 java.lang.String getAlgorithm()
          The name of the algorithm is "Blowfish".
 byte[] getKey()
          Return the key-bits for this key as an array of bytes.
 int getSize()
          Return the size of this key.
static BlowfishKey parseCDS(java.lang.String key)
          If "BlowfishKey( key )" is a valid CDS for a BlowfishKey, then BlowfishKey.parseCDS(key) will return the described BlowfishKey object.
 int plainBlockSize()
          The block-size for the Blowfish cipher is 8 bytes.
 java.lang.String toString()
          Return a CDS for this key.
 
Methods inherited from class is.logi.crypto.keys.SymmetricKey
isPrivate, matches
 
Methods inherited from class is.logi.crypto.keys.K
getFingerprint, hashCode, matchFingerprint
 
Methods inherited from class is.logi.crypto.Crypto
binString, binString, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, readInt, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlowfishKey

public BlowfishKey(int n)
Create a new random n-bit Blowfish key. The size will be rounded up to the next multiple of 8.

BlowfishKey

public BlowfishKey()
Create a new random 128 bit Blowfish key.

BlowfishKey

public BlowfishKey(byte[] key)
Create a new Blowfish key with the key bits from key.
Method Detail

parseCDS

public static BlowfishKey parseCDS(java.lang.String key)
                            throws InvalidCDSException
If "BlowfishKey( key )" is a valid CDS for a BlowfishKey, then BlowfishKey.parseCDS(key) will return the described BlowfishKey object.

A valid CDS can be created by calling the BlowfishKey.toString() method.

Throws:
InvalidCDSException - if the CDS is malformed.
See Also:
Crypto.fromString(String)

plainBlockSize

public int plainBlockSize()
The block-size for the Blowfish cipher is 8 bytes.
Specified by:
plainBlockSize in interface CipherKey

cipherBlockSize

public int cipherBlockSize()
The block-size for the Blowfish cipher is 8 bytes.
Specified by:
cipherBlockSize in interface CipherKey

getSize

public int getSize()
Return the size of this key.
Overrides:
getSize in class K

getAlgorithm

public java.lang.String getAlgorithm()
The name of the algorithm is "Blowfish".

equals

public boolean equals(java.lang.Object o)
Return true iff the two keys are equivalent.
Overrides:
equals in class java.lang.Object

getKey

public byte[] getKey()
Return the key-bits for this key as an array of bytes.

toString

public java.lang.String toString()
Return a CDS for this key.
Overrides:
toString in class java.lang.Object
See Also:
Crypto.fromString(java.io.Reader)

encrypt

public void encrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Encrypt one block of data. The plaintext is taken from source[i..i+7] and ciphertext is written to dest[i..i+7]
Specified by:
encrypt in interface CipherKey

decrypt

public void decrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Decrypt one block of data. The encrypted data is taken from dest[i..i+7] and plaintext is written to source[j..j+7].
Specified by:
decrypt in interface CipherKey


Copyright 1997-1999 Logi Ragnarsson