org.logi.crypto.modes
Class EncryptECB

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

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

Electronic Codebook Mode simply encrypts each block of plaintext independently. It is not as secure as for example CBC mode.

A padding engine can be passed to the constructor of the EncryptECB object to allow the encryption of data which is not a whole multiple of plaintext blocks. If no padding engine is given, then the padding used depends on the key class being used.

If the key implements the CipherKey interface, which makes it a key for a symmetric cipher, then no padding is parformed. It is upt to the user to ensure that there is a whole multiple of plaintext blocks (this can, or course, by specifying a padding engine in the constructor). Otherwise PKCS#1 padding is used, which is appropriate for RSA and Diffie-Hellman/El-Gamal.

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

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
EncryptECB()
          Create a new ECB-mode encrypt session with no key and default padding.
EncryptECB(EncryptionKey key)
          Create a new ECB-mode encrypt session with default padding.
EncryptECB(EncryptionKey key, Padding padding)
          Create a new ECB-mode encrypt session.
EncryptECB(Padding padding)
          Create a new ECB-mode encrypt session with no key.
 
Method Summary
 void close()
           
 byte[] encrypt(byte[] source, int i, int length)
          Send bytes to the EncryptECB 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

EncryptECB

public EncryptECB(EncryptionKey key,
                  Padding padding)
Create a new ECB-mode encrypt session.
Parameters:
key - The key to use for decryption.
padding - The padding engine to use.

EncryptECB

public EncryptECB(EncryptionKey key)
Create a new ECB-mode encrypt session with default padding.
Parameters:
key - The key to use for decryption.

EncryptECB

public EncryptECB(Padding padding)
Create a new ECB-mode encrypt session with no key. No encryption can be performed until the setKey() method has been called.
Parameters:
padding - The padding engine to use.

EncryptECB

public EncryptECB()
Create a new ECB-mode encrypt session with no key and default padding. 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 CryptoException
Set the key to use for encryption. Do not call this method when there may be data in the internal buffer.
Throws:
CryptoException - if there is data in the internal buffer which should be encrypted with the old key.

plainBlockSize

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

flush

public byte[] flush()
             throws PaddingException
Pads the internal buffer, encrypts it and returns the ciphertext.

encrypt

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

Encrypt length bytes from source, starting at i and return the ciphertext. Data is encrypted in blocks, so only whole blocks of ciphertext are written to dest. Any remaining plaintext will be stored and prepended to source in the next call to encrypt.


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