Overview | Package | Class | Tree | Deprecated | Index | Help
| Oracle Security Developer Tools Crypto Java API Reference 10g Release 3 (10.1.3) B25378-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.security.crypto.core
Class BlockCipher

`java.lang.Object
oracle.security.crypto.core.Coder
oracle.security.crypto.core.Cipher
oracle.security.crypto.core.BlockCipher`

Direct Known Subclasses:
  AES, Blowfish, DES, DES_EDE, RC2

public abstract class BlockCipher
extends Cipher

Defines the functionality and properties common to block ciphers such that subclasses should only have to override the `initialize()`, `encryptBlock()` and `decryptBlock()` methods.

Since:
  2.2

Field Summary
`protected int` | `blockSize` Block size of the wrapping BlockCipher.
`protected byte[]` | `iv` Initialization vector that the current processes are based off of (equivalent to the old iv from Cipher), for use in CBC mode.
`protected Padding.ID` | `paddingID` Holds the padding constant that will be used to determine the algorithm for to padding and unpadding data.

Fields inherited from class oracle.security.crypto.core.Cipher
`CBC, decryptionKey, ECB, encryptionKey, key, mode, NULL_PADDING, PKCS5_PADDING, rbs`

Constructor Summary
`protected` | `BlockCipher()` Instantiates the BlockCipher with no block size.
`protected` | `BlockCipher(int blockSize)` Instantiates the BlockCipher with the block size of the actual instance.

Method Summary
`int` | `blockSize()` Deprecated. Use `getBlockSize()`
`byte[]` | `decrypt(byte[] input, int inOff, int len, boolean unpad)` Decrypts a sequence of bytes of specified length, and, if specified, returns the unpadded plaintext.
`void` | `decrypt(byte[] input, int inOff, int len, byte[] output, int outOff)` Decrypts a sequence of bytes of specified length and places the original plaintext message in the given output buffer starting at the given offset.
`protected abstract void` | `decryptBlock(byte[] input, int inOff, byte[] output, int outOff)` Performs the block cipher's basic decryption operation on one block of ciphertext placing the result in the output buffer.
`byte[]` | `encrypt(byte[] input, int inOff, int len, boolean pad)` Encrypts a sequence of bytes of specified length and, if specified, performs padding.
`void` | `encrypt(byte[] input, int inOff, int len, byte[] output, int outOff)` Encrypts a sequence of bytes of specified length and places the resulting ciphertext in the given output buffer starting at the given offset.
`protected abstract void` | `encryptBlock(byte[] input, int inOff, byte[] output, int outOff)` Performs the block cipher's basic encryption operation on one block of plaintext placing the result in the output buffer.
`void` | `erase()` Erases any sensitive information stored in this BlockCipher object.
`int` | `getBlockSize()` Returns the block size of the cipher.
`byte[]` | `getIV()` Returns a clone of the initialization vector or null, if the IV is null.
`int` | `getPadding()` Deprecated. Use `getPaddingID()` instead.
`Padding.ID` | `getPaddingID()` Returns the Padding.ID constant value for this instance.
`abstract void` | `initialize(AlgorithmIdentifier algID, SymmetricKey key, Padding.ID paddingID)` This method may be used to initialize a `BlockCipher` with the given algorithm parameters, symmetric key, and padding descriptor.
`void` | `setIV(byte[] iv)` Deprecated. IV's should only be set when a BlockCipher is initialized. Use one of the initialize(...) methods instead.
`void` | `setPadding(int padding)` Deprecated. Padding should only be set when a BlockCipher is initialized. Use one of the initialize(...) methods instead.

Methods inherited from class oracle.security.crypto.core.Cipher
`assertDecryption, assertEncryption, cloneKey, decodeOp, decrypt, decrypt, decrypt, decryptOp, decryptOp, encodeOp, encrypt, encrypt, encrypt, encryptOp, encryptOp, getAlgID, getDecryptionKey, getEncryptionKey, getInstance, getInstance, getInstance, getInstance, getInstance, getKey, getMode, initialize, pad, releaseOp, setAlgID, setDecryptionKey, setEncryptionKey, setKey, setMode, setRandomBitsSource, unpad`

Methods inherited from class oracle.security.crypto.core.Coder
`algName, decode, decode, encode, encode, initialize`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### iv

    protected byte[] iv

  Initialization vector that the current processes are based off of (equivalent to the old iv from Cipher), for use in CBC mode.

### blockSize

    protected int blockSize

  Block size of the wrapping BlockCipher.

### paddingID

    protected Padding.ID paddingID

  Holds the padding constant that will be used to determine the algorithm for to padding and unpadding data.

Constructor Detail

### BlockCipher

    protected BlockCipher()

  Instantiates the BlockCipher with no block size. This should only be used by Ciphers that have a variable block size such as `AES`.

  By default, a BlockCipher is instantiated with mode of Cipher.ECB and padding scheme of Padding.NONE

### BlockCipher

    protected BlockCipher(int blockSize)

  Instantiates the BlockCipher with the block size of the actual instance.

  By default, a BlockCipher is instantiated with mode of Cipher.ECB and padding scheme of Padding.NONE

Method Detail

### initialize

    public abstract void initialize(AlgorithmIdentifier algID,
                                    SymmetricKey key,
                                    Padding.ID paddingID)
                             throws AlgorithmIdentifierException,
                                    InvalidKeyException,
                                    CipherException

  Description copied from class: `Cipher`
  This method may be used to initialize a `BlockCipher` with the given algorithm parameters, symmetric key, and padding descriptor.
  Overrides:
    `initialize` in class `Cipher`
  Parameters:
    `algID` - is the AlgorithmIdentifier whose params will be used to configure the cipher.
    `key` - is the SymmetricKey instance that will be cloned and used by the cipher internally. The internal instance will be erased when `Cipher.erase()` is called.
    `paddingID` - is used to indicate the type of padding that the Cipher should use. Options are Padding.NONE or Padding.PKCS5. A Cipher must be re-initialized before being used with the other Padding type.
  Throws:
    `CipherException` - is thrown if there's a problem initializing the Cipher with the given parameters.
    `AlgorithmIdentifierException` - is thrown if the algID's OID isn't valid for the Cipher instance being initialized or if the params are not valid for the algID's OID.
    `InvalidKeyException` - is thrown if there is a problem with the Key instance the Cipher is being initialized with.

### decrypt

    public byte[] decrypt(byte[] input,
                          int inOff,
                          int len,
                          boolean unpad)
                   throws CipherException

  Description copied from class: `Cipher`
  Decrypts a sequence of bytes of specified length, and, if specified, returns the unpadded plaintext.
  Specified by:
    `decrypt` in class `Cipher`
  Parameters:
    `input` - Buffer in which data to be decrypted is stored.
    `inOff` - Offset within buffer of the start of data.
    `len` - The length of the data
    `unpad` - specifies whether the plaintext should have padding removed.
  Returns:
    the plaintext bytes
  Throws:
    `CipherException` - is thrown if the Cipher was not initialized, if the Cipher was used for encryption without being re-initialized, if the data is not a multiple of the block size and no padding is specified, or if an error occurred during the decryption process.

### decrypt

    public void decrypt(byte[] input,
                        int inOff,
                        int len,
                        byte[] output,
                        int outOff)
                 throws CipherException

  Description copied from class: `Cipher`
  Decrypts a sequence of bytes of specified length and places the original plaintext message in the given output buffer starting at the given offset. This method will not attempt to unpad the result.
  Specified by:
    `decrypt` in class `Cipher`
  Parameters:
    `input` - array of bytes to decrypt
    `inOff` - offset of the start of the data to decrypt
    `len` - the length of the data to decrypt
    `output` - array to place the decrypted bytes
    `outOff` - offset of the start of the decrypted bytes
  Throws:
    `CipherException` - is thrown if the Cipher was not initialized, if the Cipher was used for encryption without being re-initialized, if the data is not a multiple of the block size, or if an error occurred during the decryption process.

### decryptBlock

    protected abstract void decryptBlock(byte[] input,
                                         int inOff,
                                         byte[] output,
                                         int outOff)
                                  throws CipherException

  Performs the block cipher's basic decryption operation on one block of ciphertext placing the result in the output buffer. Mode and padding operations are not applied.
  Parameters:
    `input` - buffer in which data to be decrypted is stored.
    `inOff` - offset within input buffer of the start of data.
    `output` - buffer to place the decrypted bytes in
    `outOff` - offset within output buffer where the encrypted bytes will be stored.
  Throws:
    `CipherException` - is thrown if the Cipher is not initialized, length of data is not equal to the block size, etc.

### encrypt

    public byte[] encrypt(byte[] input,
                          int inOff,
                          int len,
                          boolean pad)
                   throws CipherException

  Description copied from class: `Cipher`
  Encrypts a sequence of bytes of specified length and, if specified, performs padding.
  Specified by:
    `encrypt` in class `Cipher`
  Parameters:
    `input` - buffer in which data to be encrypted is stored.
    `inOff` - offset within buffer of the start of the data.
    `len` - the length of the data.
    `pad` - true if padding is to be used, false otherwise.
  Returns:
    the ciphertext bytes
  Throws:
    `CipherException` - is thrown if the Cipher was not initialized, if the Cipher was used for decryption without being re-initialized, if the data is not a multiple of the block size and no padding is specified, or if an error occurred during the encryption process.

### encrypt

    public void encrypt(byte[] input,
                        int inOff,
                        int len,
                        byte[] output,
                        int outOff)
                 throws CipherException

  Description copied from class: `Cipher`
  Encrypts a sequence of bytes of specified length and places the resulting ciphertext in the given output buffer starting at the given offset. This method will not attempt to unpad the result.
  Specified by:
    `encrypt` in class `Cipher`
  Parameters:
    `input` - array of bytes to encrypt
    `inOff` - offset of the start of data to encrypt
    `len` - the length of the data to encrypt
    `output` - array to place the encrypted bytes
    `outOff` - offset of the start of the encrypted bytes
  Throws:
    `CipherException` - is thrown if the Cipher was not initialized, if the Cipher was used for decryption without being re-initialized, if the data is not a multiple of the block size, or if an error occurred during the encryption process.

### encryptBlock

    protected abstract void encryptBlock(byte[] input,
                                         int inOff,
                                         byte[] output,
                                         int outOff)
                                  throws CipherException

  Performs the block cipher's basic encryption operation on one block of plaintext placing the result in the output buffer. Mode and padding operations are not applied.
  Parameters:
    `input` - buffer in which data to be encrypted is stored
    `inOff` - offset within input buffer of the start of data
    `output` - buffer to place the encrypted bytes in
    `outOff` - offset within output buffer where the encrypted bytes will be stored
  Throws:
    `CipherException` - is thrown if the Cipher is not initialized, length of data is not equal to the block size, etc.

### erase

    public void erase()

  Erases any sensitive information stored in this BlockCipher object.
  Overrides:
    `erase` in class `Cipher`

### getBlockSize

    public final int getBlockSize()

  Returns the block size of the cipher.
  Specified by:
    `getBlockSize` in class `Cipher`

### getIV

    public final byte[] getIV()

  Returns a clone of the initialization vector or null, if the IV is null.
  Overrides:
    `getIV` in class `Cipher`
  Returns:
    a clone of the IV or null if the Cipher isn't using one.

### getPaddingID

    public final Padding.ID getPaddingID()

  Returns the Padding.ID constant value for this instance.
  Overrides:
    `getPaddingID` in class `Cipher`
  Returns:
    the Padding.ID of the Padding used by the Cipher or null if its not a BlockCipher
  See Also:
    `Padding.ID`

### blockSize

    public final int blockSize()

  Deprecated. Use `getBlockSize()`
  Returns the block size of the cipher.
  Specified by:
    `blockSize` in class `Cipher`

### getPadding

    public int getPadding()

  Deprecated. Use `getPaddingID()` instead.
  Returns the block padding type, default is `Padding.NONE`.
  Overrides:
    `getPadding` in class `Cipher`

### setPadding

    public void setPadding(int padding)

  Deprecated. Padding should only be set when a BlockCipher is initialized. Use one of the initialize(...) methods instead.
  Sets the padding type, default is `Padding.NONE`.
  Overrides:
    `setPadding` in class `Cipher`

### setIV

    public void setIV(byte[] iv)
               throws CipherException

  Deprecated. IV's should only be set when a BlockCipher is initialized. Use one of the initialize(...) methods instead.
  If the given IV is null, the internal IV and last cipher block values are set to null.

  If the given IV is not null, the internal IV will be set to a clone of the given IV and the last cipher block value will also be set equal to the given IV.

  Overrides:
    `setIV` in class `Cipher`
  Parameters:
    `iv` - is the initialization vector to configure the BlockCipher with.
  Throws:
    `CipherException` - is thrown if the given IV's length is not equal to the block size.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Oracle Security Developer Tools Crypto Java API Reference 10g Release 3 (10.1.3) B25378-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005, 2006 , Oracle. All rights reserved.