Skip navigation links

Oracle Fusion Middleware Crypto FIPS Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10696-05


oracle.security.crypto.core
Class BlockCipher

java.lang.Object
  extended by oracle.security.crypto.core.Coder
      extended by oracle.security.crypto.core.Cipher
          extended by 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, ECB, key, mode, 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
 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.
 Padding.ID getPaddingID()
          Returns the Padding.ID constant value for this instance.
 void initialize(AlgorithmIdentifier algID, Key key, RandomBitsSource rbs)
          This method verifies the AlgorithmIdentifier's Object ID and configures the DES instance appropriately with the params of the AlgorithmIdentifier in addition to the Key.
protected  void setIV(byte[] iv)
          Sets the initialization vector for this block cipher.
 PrivateKey unwrapPrivateKey(byte[] encKey)
          Unwraps a private key using this cipher.
 SymmetricKey unwrapSymmetricKey(byte[] encKey, AlgorithmIdentifier algID)
          Unwraps a symmetric key using this cipher.
 byte[] wrapKey(PrivateKey key)
          Wraps a private key using this cipher.
 byte[] wrapKey(SymmetricKey key)
          Wraps a symmetric key using this cipher.

 

Methods inherited from class oracle.security.crypto.core.Cipher
assertDecryption, assertEncryption, assertKeyUnwrap, assertKeyWrap, cloneKey, decodeOp, decrypt, decrypt, decrypt, encodeOp, encrypt, encrypt, encrypt, finalize, getAlgID, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getMode, initialize, initialize, initialize, releaseOp

 

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

 

Methods inherited from class java.lang.Object
clone, equals, 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 void initialize(AlgorithmIdentifier algID,
                       Key key,
                       RandomBitsSource rbs)
                throws AlgorithmIdentifierException,
                       InvalidKeyException
This method verifies the AlgorithmIdentifier's Object ID and configures the DES instance appropriately with the params of the AlgorithmIdentifier in addition to the Key. Padding is set to Padding.NONE.
Specified by:
initialize in class Cipher
Parameters:
algID - The AlgorithmIdentifier whose params will be used to configure the cipher.
key - The SymmetricKey instance that will be used by the cipher internally.
rbs - The RandomBitsSourfce to use in this cipher
Throws:
AlgorithmIdentifierException - 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 - 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 - The buffer in which data to be decrypted is stored.
inOff - The 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 - 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 - The buffer in which data to be decrypted is stored.
inOff - The offset within buffer of the start of data.
len - The length of the data.
output - The array to place the decrypted bytes.
outOff - The offset of the start of the decrypted bytes.
Throws:
CipherException - 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 - 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 - The buffer in which data to be encrypted is stored.
inOff - The 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 - 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 - The array of bytes to encrypt.
inOff - The offset of the start of data to encrypt.
len - The length of the data to encrypt.
output - The array to place the encrypted bytes.
outOff - The offset of the start of the encrypted bytes.
Throws:
CipherException - 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 - If the Cipher is not initialized, length of data is not equal to the block size, etc.

wrapKey

public byte[] wrapKey(PrivateKey key)
               throws CipherException
Wraps a private key using this cipher.
Specified by:
wrapKey in class Cipher
Parameters:
key - The private key to wrap.
Returns:
The encrypted key.
Throws:
CipherException - If the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized or if an error occurred during the wrapping process.

wrapKey

public byte[] wrapKey(SymmetricKey key)
               throws CipherException
Wraps a symmetric key using this cipher.
Specified by:
wrapKey in class Cipher
Parameters:
key - The symmetric key to wrap.
Returns:
The encrypted key.
Throws:
CipherException - If the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized or if an error occurred during the wrapping process.

unwrapPrivateKey

public PrivateKey unwrapPrivateKey(byte[] encKey)
                            throws CipherException
Unwraps a private key using this cipher.
Specified by:
unwrapPrivateKey in class Cipher
Parameters:
encKey - The encrypted key.
Returns:
The unwrapped private key.
Throws:
If - the Cipher was not initialized, if the Cipher was used for wrapping without being re-initialized, if the key is not a private key or if an error occurred during the wrapping process.
CipherException - If the Cipher was not initialized, if the Cipher was used for unwrapping without being re-initialized or if an error occurred during the decryption process.

unwrapSymmetricKey

public SymmetricKey unwrapSymmetricKey(byte[] encKey,
                                       AlgorithmIdentifier algID)
                                throws CipherException
Unwraps a symmetric key using this cipher.
Specified by:
unwrapSymmetricKey in class Cipher
Parameters:
encKey - The encrypted key.
algID - The algorithm identifier of the wrapped symmetric key.
Returns:
The unwrapped symmetric key.
Throws:
CipherException - If the Cipher was not initialized, if the Cipher was used for unwrapping without being re-initialized or if an error occurred during the encryption process.

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.

setIV

protected void setIV(byte[] iv)
              throws CipherException
Sets the initialization vector for this block cipher.
Parameters:
iv - The new IV to set.
Throws:
CipherException

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

Skip navigation links

Oracle Fusion Middleware Crypto FIPS Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10696-05


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