tribble.crypto
Class AbstractCipher

java.lang.Object
  extended bytribble.crypto.AbstractCipher
Direct Known Subclasses:
AsymmetricCipher, SymmetricCipher

public abstract class AbstractCipher
extends java.lang.Object

Abstract base class for fundamental cipher (encryption) algorithms.

Cipher objects (of type javax.crypto.Cipher) are constructed from a combination of a cipher SPI object, which is one of generic cipher algorithm types derived from class CipherSpi, and a primitive cipher algorithm, which is a class derived from this class, AbstractCipher.

Cipher algorithm implementations derived from this class are further divided into two types, SymmetricCipher and AsymmetricCipher. These two base classes implement the primitive encryption cipher algorithms that serve as the foundation upon which the rest of this cryptographic package is built. These two classes, in other words, are the fundamental encryption algorithms for this entire package.

Since:
2005-07-05
Version:
API 2, $Revision: 1.4 $ $Date: 2005/09/10 16:53:53 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2005 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

See Also:
AsymmetricCipher, SymmetricCipher, CipherSpi

Field Summary
protected  java.lang.String m_alg
          Cipher algorithm name.
protected  boolean m_decrypt
          Cipher is in decryption, not encryption, mode.
protected  boolean m_init
          Cipher has been initialized.
protected  int m_keyLen
          Cipher Key size (in bytes).
 
Constructor Summary
protected AbstractCipher(java.lang.String alg)
          Constructor.
 
Method Summary
protected abstract  void blockDecrypt(byte[] in, int inOff, byte[] out, int outOff)
          Decrypt a single block of ciphertext.
protected abstract  void blockEncrypt(byte[] in, int inOff, byte[] out, int outOff)
          Encrypt a single block of plaintext.
protected abstract  void clear()
          Reset this cipher, wiping all sensitive information.
protected  void finalize()
          Finalization.
 java.lang.String getAlgorithm()
          Retrieve the algorithm name of this cipher.
 int getKeySize()
          Retrieve the key size of this cipher.
 int[] getKeySizes()
          Retrieve the key sizes supported by this cipher.
protected abstract  void initialize(byte[] key, boolean decrypt)
          Initialize this cipher.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_alg

protected java.lang.String m_alg
Cipher algorithm name.


m_keyLen

protected int m_keyLen
Cipher Key size (in bytes).


m_decrypt

protected boolean m_decrypt
Cipher is in decryption, not encryption, mode.


m_init

protected boolean m_init
Cipher has been initialized.

Constructor Detail

AbstractCipher

protected AbstractCipher(java.lang.String alg)
Constructor.

Parameters:
alg - Cryptographic cipher algorithm name.
Since:
1.1, 2005-07-05
Method Detail

getAlgorithm

public java.lang.String getAlgorithm()
Retrieve the algorithm name of this cipher.

Returns:
Cryptographic cipher algorithm name.
Since:
1.2, 2005-07-08

getKeySize

public int getKeySize()
Retrieve the key size of this cipher. If the cipher supports more than one key size, the preferred key size is returned.

Returns:
The key size (in bytes) of this cipher algorithm (in bytes). This may return zero, in which case the cipher has not been initialized yet with a proper key.
Since:
1.2, 2005-07-08

getKeySizes

public int[] getKeySizes()
Retrieve the key sizes supported by this cipher.

Returns:
An array of key sizes (in bytes) supported by this cipher algorithm.
Since:
1.3, 2005-07-24
See Also:
getKeySize()

initialize

protected abstract void initialize(byte[] key,
                                   boolean decrypt)
                            throws java.security.InvalidKeyException
Initialize this cipher.

Parameters:
key - The encryption key for this cipher.
decrypt - If true, this indicates that this cipher is to be initialized for decrypting, otherwise it is to be initialized for encrypting.
Throws:
java.security.InvalidKeyException
Since:
1.1, 2005-07-05
See Also:
clear()

clear

protected abstract void clear()
Reset this cipher, wiping all sensitive information.

This method will be called after this cipher object is no longer needed. It should overwrite any sensitive data contained within this object (e.g., encryption key schedules). This cipher object can no longer be used after this method has been called.

Since:
1.1, 2005-07-05
See Also:
initialize()

blockEncrypt

protected abstract void blockEncrypt(byte[] in,
                                     int inOff,
                                     byte[] out,
                                     int outOff)
Encrypt a single block of plaintext.

Parameters:
in - Plaintext block of bytes to encrypt. (The size of the block is determined by the algorithm implementation.)
inOff - Index of the first byte in array in to encrypt.
out - Array that will be filled with the encrypted ciphertext bytes. (The size of the block is determined by the algorithm implementation.)
outOff - Index of the first byte of array out to fill with the encrypted ciphertext block.
Since:
1.4, 2005-09-09
See Also:
blockDecrypt(), initialize()

blockDecrypt

protected abstract void blockDecrypt(byte[] in,
                                     int inOff,
                                     byte[] out,
                                     int outOff)
Decrypt a single block of ciphertext.

Parameters:
in - Ciphertext block of bytes to decrypt. (The size of the block is determined by the algorithm implementation.)
inOff - Index of the first byte in array in to decrypt.
out - Array that will be filled with the decrypted plaintext bytes. (The size of the block is determined by the algorithm implementation.)
outOff - Index of the first byte of array out to fill with the decrypted plaintext block.
Since:
1.4, 2005-09-09
See Also:
blockEncrypt(), initialize()

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalization. This resets this cipher object (by calling clear(), wiping all sensitive information prior to this object being garbage-collected.

Throws:
java.lang.Throwable
Since:
1.1, 2005-07-05
See Also:
clear()