de.cscc.crypto.provider
Class RSACipherEngine

java.lang.Object
  extended byjavax.crypto.CipherSpi
      extended byde.cscc.crypto.provider.RSACipherEngine

public final class RSACipherEngine
extends CipherSpi

RSACipherEngine Class.

Version:
$Revision: 1.4 $
Author:
Uwe Günther

Constructor Summary
RSACipherEngine()
           
 
Method Summary
protected  byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
          Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
protected  int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
          Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
protected  int engineGetBlockSize()
          Returns the block size (in bytes) that can be processed while a multipart cipher operation.
protected  byte[] engineGetIV()
          Returns the initialization vector (IV) in a new buffer.
protected  int engineGetKeySize(Key key)
          Returns the key size of the given key object in bit.
protected  int engineGetOutputSize(int inputLen)
          Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).
protected  AlgorithmParameters engineGetParameters()
          Returns the parameters used with this cipher.
protected  void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random)
          Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
protected  void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random)
          Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
protected  void engineInit(int opmode, Key key, SecureRandom random)
          Initializes this cipher with a key and a source of randomness.
protected  void engineSetMode(String mode)
          Sets the mode of this cipher.
protected  void engineSetPadding(String padding)
          Sets the padding mechanism of this cipher.
protected  Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType)
          Unwrap a previously wrapped key.
protected  byte[] engineUpdate(byte[] input, int inputOffset, int inputLen)
          Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.
protected  int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
          Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.
protected  byte[] engineWrap(Key key)
          Wrap a key.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RSACipherEngine

public RSACipherEngine()
Method Detail

toString

public String toString()
Returns a string representation of the object.

Returns:
a string representation of the object.

engineSetMode

protected void engineSetMode(String mode)
                      throws NoSuchAlgorithmException
Sets the mode of this cipher.

Parameters:
mode - the cipher mode.
Throws:
NoSuchAlgorithmException - if the requested cipher mode does not exist.

engineSetPadding

protected void engineSetPadding(String padding)
                         throws NoSuchPaddingException
Sets the padding mechanism of this cipher.

Parameters:
padding - the padding mechanism.
Throws:
NoSuchPaddingException - if the requested padding mechanism does not exist.

engineInit

protected void engineInit(int opmode,
                          Key key,
                          SecureRandom random)
                   throws InvalidKeyException
Initializes this cipher with a key and a source of randomness.

Parameters:
opmode - the operation mode of this cipher. This is one of the following: javax.crypto.Cipher.ENCRYPT_MODE javax.crypto.Cipher.DECRYPT_MODE javax.crypto.Cipher.WRAP_MODE javax.crypto.Cipher.UNWRAP_MODE
key - the key to encrypt or to decrypt.
random - the source of randomness.
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher, this means if the key does not match to the specific opmode.
NullPointerException - if key is null.

engineInit

protected void engineInit(int opmode,
                          Key key,
                          AlgorithmParameters params,
                          SecureRandom random)
                   throws InvalidKeyException,
                          InvalidAlgorithmParameterException
Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

Parameters:
opmode - the operation mode of this cipher. This is one of the following: javax.crypto.Cipher.ENCRYPT_MODE javax.crypto.Cipher.DECRYPT_MODE javax.crypto.Cipher.WRAP_MODE javax.crypto.Cipher.UNWRAP_MODE
key - the key to encrypt or to decrypt.
params - the algorithm paramter.
random - the source of randomness.
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher.
InvalidAlgorithmParameterException - if params isn't null, because we don't support AlgorithmParameters.

engineInit

protected void engineInit(int opmode,
                          Key key,
                          AlgorithmParameterSpec params,
                          SecureRandom random)
                   throws InvalidKeyException,
                          InvalidAlgorithmParameterException
Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

Parameters:
opmode - the operation mode of this cipher. This is one of the following: javax.crypto.Cipher.ENCRYPT_MODE javax.crypto.Cipher.DECRYPT_MODE javax.crypto.Cipher.WRAP_MODE javax.crypto.Cipher.UNWRAP_MODE
key - the key to encrypt or to decrypt.
params - the algorithm paramter.
random - the source of randomness.
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher.
InvalidAlgorithmParameterException - if params isn't null, because we don't support AlgorithmParameterSpecs.

engineUpdate

protected byte[] engineUpdate(byte[] input,
                              int inputOffset,
                              int inputLen)
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

Parameters:
input - the input buffer.
inputOffset - the offset in input where the input starts.
inputLen - the input length.
Returns:
the new buffer with the result, or null if the underlying cipher is a block cipher and the input data is too short to result in a new block.
Throws:
IllegalStateException - if the Cipher was not initialized, or you invoke this method in WRAP_MODE or UNWRAP_MODE.

engineUpdate

protected int engineUpdate(byte[] input,
                           int inputOffset,
                           int inputLen,
                           byte[] output,
                           int outputOffset)
                    throws ShortBufferException
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

Parameters:
input - the input buffer.
inputOffset - the offset in input where the input starts.
inputLen - the input length.
output - the buffer for the result.
outputOffset - the offset in output where the result is stored.
Returns:
the number of bytes stored in output
Throws:
ShortBufferException - if the given output buffer is too small to hold the result.
IllegalStateException - if the Cipher was not initialized, or you invoke this method in WRAP_MODE or UNWRAP_MODE.

engineDoFinal

protected byte[] engineDoFinal(byte[] input,
                               int inputOffset,
                               int inputLen)
                        throws IllegalBlockSizeException,
                               BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

Parameters:
input - the input buffer.
inputOffset - the offset in input where the input starts.
inputLen - the input length.
Returns:
the new buffer with the finally result.
Throws:
IllegalBlockSizeException - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size.
BadPaddingException - if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.
IllegalStateException - if the Cipher was not initialized, or you invoke this method in WRAP_MODE or UNWRAP_MODE.

engineDoFinal

protected int engineDoFinal(byte[] input,
                            int inputOffset,
                            int inputLen,
                            byte[] output,
                            int outputOffset)
                     throws ShortBufferException,
                            IllegalBlockSizeException,
                            BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

Parameters:
input - the input buffer.
inputOffset - the offset in input where the input starts.
inputLen - the input length.
output - the buffer for the finally result.
outputOffset - the offset in output where the result is stored.
Returns:
the number of bytes stored in output.
Throws:
ShortBufferException - if the given output buffer is too small to hold the result.
IllegalBlockSizeException - if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size.
BadPaddingException - if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.
IllegalStateException - if the Cipher was not initialized, or you invoke this method in WRAP_MODE or UNWRAP_MODE.

engineWrap

protected byte[] engineWrap(Key key)
                     throws IllegalBlockSizeException,
                            InvalidKeyException
Wrap a key.

Parameters:
key - the key to be wrapped.
Returns:
the wrapped key.
Throws:
NullpointerException - if key.getEncoded() is null. This means the key does not support encoding.
IllegalBlockSizeException - if the unsigned number representation of the encoded key is equal or greater than the modulus of the RSAKey.
InvalidKeyException - if it is impossible or unsafe to wrap the key with this cipher (e.g., a hardware public key is being passed to a software-only cipher).
IllegalStateException - if the Cipher was not initialized, or you invoke this method in ENCRYPT_MODE or DECRTYPT_MODE.

engineUnwrap

protected Key engineUnwrap(byte[] wrappedKey,
                           String wrappedKeyAlgorithm,
                           int wrappedKeyType)
                    throws InvalidKeyException,
                           NoSuchAlgorithmException
Unwrap a previously wrapped key.

Parameters:
wrappedKey - the wrapped key to unwrap.
wrappedKeyAlgorithm - the algorithm associated with the key wrapped key.
wrappedKeyType - the type of the wrapped key. This is one of javax.crypto.Cipher.SECRET_KEY, javax.crypto.Cipher.PRIVATE_KEY, javax.crypto.Cipher.PUBLIC_KEY.
Returns:
the unwrapped key.
Throws:
InvalidKeyException - if wrappedKey does not represent a wrapped key, or if the algorithm associated with the wrapped key is different from wrappedKeyAlgorithm and/or its key type is different from wrappedKeyType.
NoSuchAlgorithmException - if no installed providers can create keys for the wrappedKeyAlgorithm.
IllegalStateException - if the Cipher was not initialized.

engineGetBlockSize

protected int engineGetBlockSize()
Returns the block size (in bytes) that can be processed while a multipart cipher operation.

Returns:
the input block size (in bytes).
Throws:
IllegalStateException - if the Cipher was not initialized or a opmode does not match.

engineGetOutputSize

protected int engineGetOutputSize(int inputLen)
Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).

Parameters:
inputLen - the input length in bytes.
Returns:
the reqired output buffer size in bytes.
Throws:
IllegalStateException - if the Cipher was not initialized or a opmode does not match.

engineGetKeySize

protected int engineGetKeySize(Key key)
                        throws InvalidKeyException
Returns the key size of the given key object in bit. This method will be invoked trough the JCE before engineInit is invoked.

Parameters:
key - the key object.
Returns:
the key size of the given key object.
Throws:
InvalidKeyException - if key is invalid.

engineGetParameters

protected AlgorithmParameters engineGetParameters()
Returns the parameters used with this cipher.

Returns:
the parameters used with this cipher, or null if this cipher does not use any parameters.
Throws:
IllegalStateException - if the Cipher was not initialized.

engineGetIV

protected byte[] engineGetIV()
Returns the initialization vector (IV) in a new buffer.

Returns:
the initialization vector in a new buffer, or null if the underlying algorithm does not use an IV, or if the IV has not yet been set.
Throws:
IllegalStateException - if the Cipher was not initialized.


Copyright © 2001, 2002 by Uwe GŁnther. See the COPYING file for more details. Browse the source as HTML.