org.logi.crypto.modes
Class EncryptCFB

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.modes.EncryptMode
              |
              +--org.logi.crypto.modes.EncryptCFB
All Implemented Interfaces:
EncryptSession

public class EncryptCFB
extends org.logi.crypto.modes.EncryptMode

This class implements 8-bit Cipherblock FeedBack mode which encrypts a whole block for each plaintext character. This makes it much slower than the ECB, CBC and OFB modes.

CFB mode is also inherently incompatible with probabilistic encryption algorithms such as ElGamal (implemented in the DHKey class) since it relies on the same keystream being gengerated by the encrypting and decrypting processes.

Author:
Logi Ragnarsson (logir@logi.org)
See Also:
DecryptCFB

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
EncryptCFB()
          Create a new CBF-mode encrypt session with no key.
EncryptCFB(EncryptionKey key)
          Create a new CBF-mode encrypt session with the specified key.
 
Method Summary
 void close()
           
 byte[] encrypt(byte[] source, int i, int length)
          Send bytes to the EncryptCFB object for encryption.
 void finalize()
           
 byte[] flush()
          Pads the internal buffer, encrypts it and returns the ciphertext.
 byte[] flush(byte[] source, int i, int length)
          Equivalent to calling encrypt(source,i,length) followed by flush().
 EncryptionKey getKey()
          Return the key used for encryption.
 int plainBlockSize()
          Return the size of the blocks of plaintext encrypted by this object.
 void setKey(EncryptionKey key)
          Set the key to use for encryption.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncryptCFB

public EncryptCFB(EncryptionKey key)
           throws KeyException
Create a new CBF-mode encrypt session with the specified key.
Throws:
KeyException - if key is a public key.

EncryptCFB

public EncryptCFB()
Create a new CBF-mode encrypt session with no key. No encryption can be performed until the setKey() method has been called.
Method Detail

getKey

public EncryptionKey getKey()
Return the key used for encryption.

setKey

public void setKey(EncryptionKey key)
            throws KeyException
Set the key to use for encryption.
Throws:
KeyException - if key is a public key.

plainBlockSize

public int plainBlockSize()
Return the size of the blocks of plaintext encrypted by this object.

flush

public byte[] flush()
Pads the internal buffer, encrypts it and returns the ciphertext. Since CBF mode doesn't use an internal buffer, an empty array is returned.

encrypt

public byte[] encrypt(byte[] source,
                      int i,
                      int length)
Send bytes to the EncryptCFB object for encryption.

Encrypt length bytes from source, starting at i and return the ciphertext.


flush

public byte[] flush(byte[] source,
                    int i,
                    int length)
             throws PaddingException
Equivalent to calling encrypt(source,i,length) followed by flush().
Specified by:
flush in interface EncryptSession

close

public void close()

finalize

public void finalize()


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL