tribble.crypto
Class AsymmetricCipher

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

public abstract class AsymmetricCipher
extends AbstractCipher

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.

Since:
2003-03-23
Version:
API 2, $Revision: 1.5 $ $Date: 2005/09/10 17:15:20 $
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 Also:
SymmetricCipher, CipherSpi

Field Summary
 
Fields inherited from class tribble.crypto.AbstractCipher
m_alg, m_decrypt, m_init, m_keyLen
 
Constructor Summary
protected AsymmetricCipher(java.lang.String alg)
          Constructor.
protected AsymmetricCipher(java.lang.String alg, int blockLen)
          Constructor.
 
Method Summary
protected abstract  void blockDecrypt(byte[] in, int inOff, byte[] out, int outOff)
          Decrypt a single block of bytes using this cipher.
protected abstract  void blockEncrypt(byte[] in, int inOff, byte[] out, int outOff)
          Encrypt a single block of bytes using this cipher.
abstract  int getCipherBlockSize()
          Retrieve the ciphertext block size (in bytes) of this cipher.
abstract  int getPlainBlockSize()
          Retrieve the plaintext block size (in bytes) of this cipher.
protected abstract  void initialize(java.security.spec.KeySpec key, boolean decrypt)
          Initialize this cipher.
 
Methods inherited from class tribble.crypto.AbstractCipher
clear, finalize, getAlgorithm, getKeySize, getKeySizes, initialize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsymmetricCipher

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

Parameters:
alg - Cryptographic cipher algorithm name.
Since:
1.5, 2005-09-09

AsymmetricCipher

protected AsymmetricCipher(java.lang.String alg,
                           int blockLen)
Constructor.

Parameters:
alg - Cryptographic cipher algorithm name.
blockLen - Cipher block size (in bytes), which is ignored.
Since:
1.5, 2005-09-09
Method Detail

getPlainBlockSize

public abstract int getPlainBlockSize()
Retrieve the plaintext block size (in bytes) of this cipher.

Returns:
The size, in bytes, of the plaintext blocks to use with this cipher.
Since:
1.2, 2003-03-22
See Also:
getCipherBlockSize()

getCipherBlockSize

public abstract int getCipherBlockSize()
Retrieve the ciphertext block size (in bytes) of this cipher.

Returns:
The size, in bytes, of the ciphertext blocks to use with this cipher.
Since:
1.2, 2003-03-22
See Also:
getPlainBlockSize()

initialize

protected abstract void initialize(java.security.spec.KeySpec key,
                                   boolean decrypt)
                            throws java.security.InvalidKeyException
Initialize this cipher.

Parameters:
key - The asymmetric (public or private) key for this cipher. This is either a java.security.PublicKey or a java.security.PrivateKey object.
decrypt - Specifies that this cipher is to be set up in decryption mode.
Throws:
java.security.InvalidKeyException
Since:
1.5, 2005-09-09

blockEncrypt

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

Specified by:
blockEncrypt in class AbstractCipher
Parameters:
in - Plaintext block of bytes to encrypt. The length of this block is the value returned by getPlainBlockSize().
inOff - Index of the first byte in array in to encrypt.
out - Array that will be filled with the encrypted ciphertext bytes. The length of this block is the value returned by getCipherBlockSize().
outOff - Index of the first byte of array out to fill with the encrypted ciphertext block.
Since:
1.5, 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 bytes using this cipher.

Specified by:
blockDecrypt in class AbstractCipher
Parameters:
in - Ciphertext block of bytes to decrypt. The length of this block is the value returned by getCipherBlockSize().
inOff - Index of the first byte in array in to decrypt.
out - Array that will be filled with the decrypted plaintext bytes. The length of this block is the value returned by getPlainBlockSize().
outOff - Index of the first byte of array out to fill with the decrypted plaintext block.
Since:
1.5, 2005-09-09
See Also:
blockEncrypt(), initialize()