//============================================================================== // AsymmetricCipher.java //============================================================================== package tribble.crypto; // System imports import java.security.InvalidKeyException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.KeySpec; /******************************************************************************* * Asymmetric (public key) block cipher base class. * *
* This base class provides the foundation for cipher (encryption) algorithm * implementations having fixed-length blocks and key lengths, and which utilize * a public/private (asymmetric) key pair for encryption and decryption. * * * @version API 2, $Revision: 1.5 $ $Date: 2005/09/10 17:15:20 $ * @since 2003-03-23 * @author * David R. Tribble * (david@tribble.com). * *
* Copyright ©2003-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 SymmetricCipher
* @see CipherSpi
*/
public abstract class AsymmetricCipher
extends tribble.crypto.AbstractCipher
{
// Identification
/** Revision information. */
static final String REV =
"@(#)tribble/crypto/AsymmetricCipher.java $Revision: 1.5 $ $Date: 2005/09/10 17:15:20 $\n";
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Variables
// (None)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Constructors
/***************************************************************************
* Constructor.
*
* @param alg
* Cryptographic cipher algorithm name.
*
* @since 1.5, 2005-09-09
*/
protected AsymmetricCipher(String alg)
{
// Initialize
super(alg);
}
/***************************************************************************
* Constructor.
*
* @param alg
* Cryptographic cipher algorithm name.
*
* @param blockLen
* Cipher block size (in bytes), which is ignored.
*
* @since 1.5, 2005-09-09
*/
protected AsymmetricCipher(String alg, int blockLen)
{
// Initialize
super(alg);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Methods
/***************************************************************************
* Retrieve the plaintext block size (in bytes) of this cipher.
*
* @return
* The size, in bytes, of the plaintext blocks to use with this cipher.
*
* @see #getCipherBlockSize getCipherBlockSize()
*
* @since 1.2, 2003-03-22
*/
public abstract int getPlainBlockSize();
/***************************************************************************
* Retrieve the ciphertext block size (in bytes) of this cipher.
*
* @return
* The size, in bytes, of the ciphertext blocks to use with this cipher.
*
* @see #getPlainBlockSize getPlainBlockSize()
*
* @since 1.2, 2003-03-22
*/
public abstract int getCipherBlockSize();
/***************************************************************************
* Initialize this cipher.
*
* @param key
* The asymmetric (public or private) key for this cipher.
* This is either a java.security.PublicKey or a
* java.security.PrivateKey object.
*
* @param decrypt
* Specifies that this cipher is to be set up in decryption mode.
*
* @since 1.5, 2005-09-09
*/
protected abstract void initialize(/*const*/ KeySpec key, boolean decrypt)
throws InvalidKeyException;
/***************************************************************************
* Encrypt a single block of bytes using this cipher.
*
* @param in
* Plaintext block of bytes to encrypt.
* The length of this block is the value returned by
* {@link #getPlainBlockSize getPlainBlockSize()}.
*
* @param inOff
* Index of the first byte in array in to encrypt.
*
* @param out
* Array that will be filled with the encrypted ciphertext bytes.
* The length of this block is the value returned by
* {@link #getCipherBlockSize getCipherBlockSize()}.
*
* @param outOff
* Index of the first byte of array out to fill with the encrypted
* ciphertext block.
*
* @see #blockDecrypt blockDecrypt()
* @see #initialize initialize()
*
* @since 1.5, 2005-09-09
*/
protected abstract void blockEncrypt(/*const*/ byte[] in, int inOff,
byte[] out, int outOff);
/***************************************************************************
* Decrypt a single block of bytes using this cipher.
*
* @param in
* Ciphertext block of bytes to decrypt.
* The length of this block is the value returned by
* {@link #getCipherBlockSize getCipherBlockSize()}.
*
* @param inOff
* Index of the first byte in array in to decrypt.
*
* @param out
* Array that will be filled with the decrypted plaintext bytes.
* The length of this block is the value returned by
* {@link #getPlainBlockSize getPlainBlockSize()}.
*
* @param outOff
* Index of the first byte of array out to fill with the decrypted
* plaintext block.
*
* @see #blockEncrypt blockEncrypt()
* @see #initialize initialize()
*
* @since 1.5, 2005-09-09
*/
protected abstract void blockDecrypt(/*const*/ byte[] in, int inOff,
byte[] out, int outOff);
}
// End AsymmetricCipher.java