Class javax.crypto.Cipher
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class javax.crypto.Cipher

java.lang.Object
   |
   +----javax.crypto.Cipher

public class Cipher
extends Object
A parent class for encryption/decryption objects.

Variable Index

 o DECRYPT_MODE
 o ENCRYPT_MODE
 o ident

Constructor Index

 o Cipher(CipherSpi, Provider, String)
Creates a Cipher object.

Method Index

 o doFinal()
Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialised.
 o doFinal(byte[])
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
 o doFinal(byte[], int)
Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialised.
 o doFinal(byte[], int, int)
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
 o doFinal(byte[], int, int, byte[])
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
 o doFinal(byte[], int, int, byte[], int)
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
 o getBlockSize()
Returns the block size (in bytes).
 o getInstance(String, String)
Generates a Cipher object implementing the specified algorithm from the specified provider.
 o getIV()
Returns the initialisation vector (IV) in a new buffer.
 o getOutputSize(int)
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).
 o init(int, Key)
Initialises this cipher for mode opmode, using the specified key.
 o init(int, Key, AlgorithmParameterSpec)
 o init(int, Key, AlgorithmParameterSpec, SecureRandom)
 o init(int, Key, SecureRandom)
Initialises this cipher for mode opmode, using the specified key.
 o update(byte[])
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.
 o update(byte[], int, int)
Encrypts or decrypts the specified subarray of data.
 o update(byte[], int, int, byte[])
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.
 o update(byte[], int, int, byte[], int)
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.

Variables

 o ident
  public final static String ident
 o ENCRYPT_MODE
  public final static int ENCRYPT_MODE
 o DECRYPT_MODE
  public final static int DECRYPT_MODE

Constructors

 o Cipher
  protected Cipher(CipherSpi cipherSpi,
                   Provider provider,
                   String transformation)
Creates a Cipher object.
Parameters:
cipherSpi - the delegate
provider - the provider
transformation - the transformation

Methods

 o getInstance
  public static Cipher getInstance(String transformation,
                                   String provider) throws NoSuchAlgorithmException, NoSuchProviderException
Generates a Cipher object implementing the specified algorithm from the specified provider. For block ciphers, this method returns a block cipher in ECB mode, with no padding. A more specialised getInstance method should be called if a block cipher implementing a different mode and padding scheme is desired.

Only the ABA provider is supported.

Throws: NoSuchAlgorithmException
- if the algorithm is not available in the environment.
Throws: NoSuchProviderException
- if the provider is not available in the environment.
 o getBlockSize
  public int getBlockSize()
Returns the block size (in bytes).
Returns:
the block size (in bytes), or 0 if the underlying algorithm is not a block cipher
 o getOutputSize
  public int getOutputSize(int inputLen) throws IllegalStateException
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).

This call takes into account any unprocessed (buffered) data from a previous update call, and padding. The actual output length of the next update or doFinal call may be smaller than the length returned by this method.

Parameters:
inputLen - the input length (in bytes)
Returns:
the required output buffer size (in bytes)
Throws: IllegalStateException
if this cipher is in a wrong state (e.g., has not yet been initialised)
 o getIV
  public byte[] getIV()
Returns the initialisation vector (IV) in a new buffer.

This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.

Returns:
the initialisation 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.
 o init
  public final void init(int opmode,
                         Key key) throws IllegalStateException, KeyException
Initialises this cipher for mode opmode, using the specified key. This method may be called on a cipher in any state. Any state information (key, feedback buffer,...) is lost and reset.
 o init
  public final void init(int opmode,
                         Key key,
                         SecureRandom random) throws IllegalStateException, KeyException
Initialises this cipher for mode opmode, using the specified key. This method may be called on a cipher in any state. Any state information (key, feedback buffer,...) is lost and reset.
 o init
  public final void init(int opmode,
                         Key key,
                         AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException
 o init
  public final void init(int opmode,
                         Key key,
                         AlgorithmParameterSpec params,
                         SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
 o update
  public final byte[] update(byte input[]) throws IllegalStateException
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.

The bytes in the input buffer are processed, and the result is stored in a new buffer.

Parameters:
input - the input buffer
Returns:
the new buffer with the result
Throws: IllegalStateException
if the cipher is in a wrong state (e.g. not initialised).
 o update
  public final byte[] update(byte input[],
                             int inputOffset,
                             int inputLen) throws IllegalStateException
Encrypts or decrypts the specified subarray of data. Whether the data is encrypted or decrypted depends on the cipher's initialisation state. This method will automatically allocate an output buffer of the right size.
 o update
  public final int update(byte input[],
                          int inputOffset,
                          int inputLen,
                          byte output[]) throws IllegalStateException, ShortBufferException
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset, are processed, and the result is stored in the output buffer, starting at outputOffset.

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: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
Throws: ShortBufferException
if the given output buffer is too small to hold the result
 o update
  public final int update(byte input[],
                          int inputOffset,
                          int inputLen,
                          byte output[],
                          int outputOffset) throws IllegalStateException, ShortBufferException
Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialised), processing another data part.

The first inputLen bytes in the input buffer, starting at inputOffset, are processed, and the result is stored in the output buffer, starting at outputOffset.

If the output buffer is too small to hold the result, a ShortBufferException is thrown. In this case, repeat this call with a larger output buffer. Use getOutputSize to determine how big the output buffer should be.

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: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
Throws: ShortBufferException
if the given output buffer is too small to hold the result
 o doFinal
  public final byte[] doFinal() throws IllegalStateException, IllegalBlockSizeException, BadPaddingException
Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialised.

Input data that may have been buffered during a previous update operation is processed, with padding (if requested) being applied. The result is stored in a new buffer.

The cipher is reset to its initial state (uninitialised) after this call.

Returns:
s the new buffer with the result
Throws: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: 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.
 o doFinal
  public final int doFinal(byte output[],
                           int outputOffset) throws IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException
Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialised.

Input data that may have been buffered during a previous update operation is processed, with padding (if requested) being applied. The result is stored in the output buffer, starting at outputOffset.

If the output buffer is too small to hold the result, a ShortBufferException is thrown. In this case, repeat this call with a larger output buffer. Use getOutputSize to determine how big the output buffer should be.

Parameters:
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: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: ShortBufferException
if the given output buffer is too small to hold the result
Throws: 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
 o doFinal
  public final byte[] doFinal(byte input[]) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialised.

The bytes in the input buffer, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. The result is stored in a new buffer.

Parameters:
input - - the input buffer
Returns:
s the new buffer with the result
Throws: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: 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
 o doFinal
  public final byte[] doFinal(byte input[],
                              int inputOffset,
                              int inputLen) throws IllegalStateException, IllegalBlockSizeException, BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialised.

The first inputLen bytes in the input buffer, starting at inputOffset, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. The result is stored in a new buffer.

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
Throws: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: 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
 o doFinal
  public final int doFinal(byte input[],
                           int inputOffset,
                           int inputLen,
                           byte output[]) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialised.

The first inputLen bytes in the input buffer, starting at inputOffset, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. The result is stored in the output buffer.

If the output buffer is too small to hold the result, a ShortBufferException is thrown. In this case, repeat this call with a larger output buffer. Use getOutputSize to determine how big the output buffer should be.

Parameters:
input - - the input buffer
inputOffset - - the offset in input where the input starts
inputLen - - the input length
output - - the buffer for the result
Returns:
the number of bytes stored in output
Throws: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: ShortBufferException
if the given output buffer is too small to hold the result
Throws: 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
 o doFinal
  public final int doFinal(byte input[],
                           int inputOffset,
                           int inputLen,
                           byte output[],
                           int outputOffset) throws IllegalStateException, ShortBufferException, IllegalBlockSizeException, BadPaddingException
Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialised.

The first inputLen bytes in the input buffer, starting at inputOffset, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. The result is stored in the output buffer, starting at outputOffset.

If the output buffer is too small to hold the result, a ShortBufferException is thrown. In this case, repeat this call with a larger output buffer. Use getOutputSize to determine how big the output buffer should be.

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: IllegalStateException
if this cipher is in a wrong state (e.g., has not been initialised)
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
Throws: ShortBufferException
if the given output buffer is too small to hold the result
Throws: 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

All Packages  Class Hierarchy  This Package  Previous  Next  Index