de.cscc.crypto.provider
Class DESede3KeyCipherEngine

java.lang.Object
  extended byjavax.crypto.CipherSpi
      extended byde.cscc.crypto.provider.DESBaseCipherEngine
          extended byde.cscc.crypto.provider.DESede3KeyCipherEngine

public final class DESede3KeyCipherEngine
extends de.cscc.crypto.provider.DESBaseCipherEngine

This is the concret DESede3Key algorithm class, it subclasses DESBaseCipherEngine, because in JCE is no possiblity to set a cipher.


Constructor Summary
DESede3KeyCipherEngine()
          Creates a new DESede3KeyCipherEngine object.
 
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).
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.
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

DESede3KeyCipherEngine

public DESede3KeyCipherEngine()
Creates a new DESede3KeyCipherEngine object.

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, or if this cipher is being initialized for decryption and requires algorithm parameters that cannot be determinated from the given key.

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 the given algorithm parameters are inappropriate for this cipher, or if this cipher is being initialized for decryption and requires algorithm parameters and params is null.

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 the given algorithm parameters are inappropriate for this cipher, or if this cipher is being initialized for decryption and requires algorithm parameters and params is null.

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.

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.

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.

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.

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.

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.

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.

engineGetBlockSize

protected int engineGetBlockSize()
Returns the block size (in bytes).

Returns:
the block size (in bytes), or 0 if the underlying algorithm is not a block cipher

engineGetKeySize

protected int engineGetKeySize(Key key)
                        throws InvalidKeyException
Returns the key size of the given key object.

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

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.

engineWrap

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

Parameters:
key - the key to be wrapped.
Returns:
the wrapped key.
Throws:
IllegalBlockSizeException - if this cipher is a block cipher, no padding has been requested, and the length of the encoding of the key to be wrapped is not a multiple of the block size.
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).


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