tribble.crypto
Class RSACipher

java.lang.Object
  extended bytribble.crypto.AbstractCipher
      extended bytribble.crypto.AsymmetricCipher
          extended bytribble.crypto.RSACipher

public final class RSACipher
extends AsymmetricCipher

RSA, an asymmetric (public key) cipher.

RSA was invented in 1978 by Ron Rivest, Adi Shamir, and Leonard Adleman of Public Key Partners (PKP). Two weeks before the patent for RSA was due to expire in Sep 2000, PKP placed the algorithm into the public domain.

Since:
2003-03-17
Version:
API 2, $Revision: 1.5 $ $Date: 2005/09/11 04:22:22 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2003-2005 by David R. Tribble, all rights reserved.

THIS CODE MAY BE SUBJECT TO U.S. EXPORT RESTRICTIONS, AND SHOULD NOT BE EXPORTED OUTSIDE THE BORDERS OF THE UNITED STATES OF AMERICA.
Within the confines of the U.S., however, permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.


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

Constructor Detail

RSACipher

public RSACipher()
Constructor.

Since:
1.1, 2003-03-17
Method Detail

getPlainBlockSize

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

Due to the nature of the underlying arithmetic of the algorithm used, the plaintext block size is always one byte shorter than the ciphertext block size (which is the same size as the modulus).

Specified by:
getPlainBlockSize in class AsymmetricCipher
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 int getCipherBlockSize()
Retrieve the ciphertext block size (in bytes) of this cipher.

Due to the nature of the underlying arithmetic of the algorithm used, the ciphertext block size is the same size as the modulus, and is always one byte longer than the plaintext block size.

Specified by:
getCipherBlockSize in class AsymmetricCipher
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 void initialize(byte[] key,
                          boolean decrypt)
                   throws java.security.InvalidKeyException
Initialize this cipher.

Specified by:
initialize in class AbstractCipher
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.5, 2005-07-05
See Also:
initialize(), clear()

initialize

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

Specified by:
initialize in class AsymmetricCipher
Parameters:
key - The asymmetric (public or private) key for this cipher. This is an RSA public or private key.
decrypt - Specifies that this cipher is to be set up in decryption mode.
Throws:
java.security.InvalidKeyException
Since:
1.1, 2003-03-20
See Also:
clear()

clear

protected 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.

Specified by:
clear in class AbstractCipher
Since:
1.5, 2005-07-07
See Also:
initialize()

blockEncrypt

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

Specified by:
blockEncrypt in class AsymmetricCipher
Parameters:
in - A block of bytes to encrypt. The number of plaintext bytes read from the block is the length returned by getPlainBlockSize().
inOff - The index of the first byte of array in to encrypt.
out - An array that will be filled with the encrypted bytes. The number of ciphertext bytes written to the block is the length returned by getCipherBlockSize().
outOff - The index of the first byte of array out to fill.
Since:
1.1, 2003-03-20
See Also:
blockDecrypt()

blockDecrypt

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

Specified by:
blockDecrypt in class AsymmetricCipher
Parameters:
in - A block of bytes to decrypt. The number of ciphertext bytes read from the block is the length returned by getCipherBlockSize().
inOff - The index of the first byte of array in to decrypt.
out - An array that will be filled with the decrypted bytes. The number of plaintext bytes written to the block is the length returned by getPlainBlockSize().
outOff - The index of the first byte of array out to fill.
Since:
1.1, 2003-03-20
See Also:
blockEncrypt()