For the latest news and information visit
The GNU Crypto project

gnu.crypto.jce.cipher
Class CipherAdapter

java.lang.Object
  extended byjavax.crypto.CipherSpi
      extended bygnu.crypto.jce.cipher.CipherAdapter
Direct Known Subclasses:
AESSpi, AnubisSpi, BlowfishSpi, Cast5Spi, DESSpi, KhazadSpi, NullCipherSpi, PBES2, RijndaelSpi, SerpentSpi, SquareSpi, TripleDESSpi, TwofishSpi

class CipherAdapter
extends javax.crypto.CipherSpi

The implementation of a generic Cipher Adapter class to wrap GNU Crypto cipher instances.

This class defines the Service Provider Interface (SPI) for the Cipher class, which provides the functionality of symmetric-key block ciphers, such as the AES.

This base class defines all of the abstract methods in CipherSpi, but does not define the (non-abstract) key wrapping functions that extended the base cipher SPI, and these methods thus immediately throw an UnsupportedOperationException. If a cipher implementation provides this functionality, or if it in fact accepts parameters other than the key and the initialization vector, the subclass should override those methods. Otherwise a subclass need only call the CipherAdapter(String) constructor with the name of the cipher.

Version:
$Revision: 1.2 $

Field Summary
protected  java.util.Map attributes
          Our attributes map.
protected  int blockLen
          The length of blocks we are processing.
protected  IBlockCipher cipher
          Our cipher instance.
protected  int keyLen
          The current key size.
protected  IMode mode
          Our mode instance.
protected  IPad pad
          Our padding instance.
protected  byte[] partBlock
          An incomplete block.
protected  int partLen
          The number of bytes in partBlock.
 
Constructor Summary
protected CipherAdapter(java.lang.String cipherName)
          Creates a new cipher adapter with the default block size.
protected CipherAdapter(java.lang.String cipherName, int blockLen)
          Protected constructor to be called by subclasses.
 
Method Summary
protected  byte[] engineDoFinal(byte[] input, int off, int len)
           
protected  int engineDoFinal(byte[] in, int inOff, int inLen, byte[] out, int outOff)
           
protected  int engineGetBlockSize()
           
protected  byte[] engineGetIV()
           
protected  int engineGetOutputSize(int inputLen)
           
protected  java.security.AlgorithmParameters engineGetParameters()
           
protected  void engineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
           
protected  void engineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)
           
protected  void engineInit(int opmode, java.security.Key key, java.security.SecureRandom random)
           
protected  void engineSetMode(java.lang.String modeName)
           
protected  void engineSetPadding(java.lang.String padName)
           
protected  byte[] engineUpdate(byte[] input, int off, int len)
           
protected  int engineUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff)
           
 
Methods inherited from class javax.crypto.CipherSpi
engineGetKeySize, engineUnwrap, engineWrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cipher

protected IBlockCipher cipher
Our cipher instance.


mode

protected IMode mode
Our mode instance.


pad

protected IPad pad
Our padding instance.


keyLen

protected int keyLen
The current key size.


attributes

protected java.util.Map attributes
Our attributes map.


partBlock

protected byte[] partBlock
An incomplete block.


partLen

protected int partLen
The number of bytes in partBlock.


blockLen

protected int blockLen
The length of blocks we are processing.

Constructor Detail

CipherAdapter

protected CipherAdapter(java.lang.String cipherName,
                        int blockLen)

Protected constructor to be called by subclasses. The cipher name argument should be the appropriate one listed in Registry. The basic cipher instance is created, along with an instance of the ECB mode and no padding.

Parameters:
cipherName - The cipher to instantiate.
blockLen - The block length to use.

CipherAdapter

protected CipherAdapter(java.lang.String cipherName)

Creates a new cipher adapter with the default block size.

Parameters:
cipherName - The cipher to instantiate.
Method Detail

engineSetMode

protected void engineSetMode(java.lang.String modeName)
                      throws java.security.NoSuchAlgorithmException
Throws:
java.security.NoSuchAlgorithmException

engineSetPadding

protected void engineSetPadding(java.lang.String padName)
                         throws javax.crypto.NoSuchPaddingException
Throws:
javax.crypto.NoSuchPaddingException

engineGetBlockSize

protected int engineGetBlockSize()

engineGetOutputSize

protected int engineGetOutputSize(int inputLen)

engineGetIV

protected byte[] engineGetIV()

engineGetParameters

protected java.security.AlgorithmParameters engineGetParameters()

engineInit

protected void engineInit(int opmode,
                          java.security.Key key,
                          java.security.SecureRandom random)
                   throws java.security.InvalidKeyException
Throws:
java.security.InvalidKeyException

engineInit

protected void engineInit(int opmode,
                          java.security.Key key,
                          java.security.spec.AlgorithmParameterSpec params,
                          java.security.SecureRandom random)
                   throws java.security.InvalidKeyException,
                          java.security.InvalidAlgorithmParameterException
Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException

engineInit

protected void engineInit(int opmode,
                          java.security.Key key,
                          java.security.AlgorithmParameters params,
                          java.security.SecureRandom random)
                   throws java.security.InvalidKeyException,
                          java.security.InvalidAlgorithmParameterException
Throws:
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException

engineUpdate

protected byte[] engineUpdate(byte[] input,
                              int off,
                              int len)

engineUpdate

protected int engineUpdate(byte[] in,
                           int inOff,
                           int inLen,
                           byte[] out,
                           int outOff)
                    throws javax.crypto.ShortBufferException
Throws:
javax.crypto.ShortBufferException

engineDoFinal

protected byte[] engineDoFinal(byte[] input,
                               int off,
                               int len)
                        throws javax.crypto.IllegalBlockSizeException,
                               javax.crypto.BadPaddingException
Throws:
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

engineDoFinal

protected int engineDoFinal(byte[] in,
                            int inOff,
                            int inLen,
                            byte[] out,
                            int outOff)
                     throws javax.crypto.BadPaddingException,
                            javax.crypto.IllegalBlockSizeException,
                            javax.crypto.ShortBufferException
Throws:
javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
javax.crypto.ShortBufferException

For the latest news and information visit
The GNU Crypto project

Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.