com.mindbright.jce.crypto
Class Cipher

java.lang.Object
  extended by com.mindbright.jce.crypto.Cipher

public class Cipher
extends java.lang.Object


Field Summary
static int DECRYPT_MODE
           
static int ENCRYPT_MODE
           
 
Constructor Summary
protected Cipher(CipherSpi cipherSpi, Provider provider, java.lang.String transformation)
           
 
Method Summary
 byte[] doFinal(byte[] input)
          Encrypt the entire input array.
 byte[] doFinal(byte[] input, int inputOffset, int inputLen)
          Encrypt part of the input array
 int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output)
          Encrypt part of the input array and stores the result in the given output array.
 int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
          Encrypt part of the input array and stores the result in the given output array.
 java.lang.String getAlgorithm()
          Get the name of the algorithm implemented by this Cipher instance.
 int getBlockSize()
          Get how big blocks this algorithm works on.
static Cipher getInstance(java.lang.String transformation)
          Get a Cipher instance which implements the given algorithm in any of the registered providers.
static Cipher getInstance(java.lang.String transformation, java.lang.String provider)
          Get a Cipher instance which implements the given algorithm in the given provider.
 byte[] getIV()
          Get the IV used by this instance
 int getOutputSize(int inputLen)
          Calculate how much encryted data an imput of the given length will cause.
 Provider getProvider()
          Get the provider which implements this algorithm.
 void init(int opmode, Key key)
          Initialize this Cipher instance.
 void init(int opmode, Key key, AlgorithmParameterSpec params)
          Initialize this Cipher instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DECRYPT_MODE

public static final int DECRYPT_MODE
See Also:
Constant Field Values

ENCRYPT_MODE

public static final int ENCRYPT_MODE
See Also:
Constant Field Values
Constructor Detail

Cipher

protected Cipher(CipherSpi cipherSpi,
                 Provider provider,
                 java.lang.String transformation)
Method Detail

doFinal

public final byte[] doFinal(byte[] input)
Encrypt the entire input array.

Note that the input must be a multiple of the block size bytes long.

Parameters:
input - array of data to encrypt
Returns:
the encrypted data

doFinal

public final byte[] doFinal(byte[] input,
                            int inputOffset,
                            int inputLen)
Encrypt part of the input array

Note that the input must be a multiple of the block size bytes long.

Parameters:
input - array of data to encrypt
inputOffset - start of data to encrypt
inputLen - length of data to encrypt
Returns:
the encrypted data

doFinal

public final int doFinal(byte[] input,
                         int inputOffset,
                         int inputLen,
                         byte[] output)
Encrypt part of the input array and stores the result in the given output array.

Note that the input must be a multiple of the block size bytes long.

Parameters:
input - array of data to encrypt
inputOffset - start of data to encrypt
inputLen - length of data to encrypt
output - array in which output is stored. This array must have room for at least getOutputSize(inputLen) bytes
Returns:
the number of bytes store in the output array

doFinal

public final int doFinal(byte[] input,
                         int inputOffset,
                         int inputLen,
                         byte[] output,
                         int outputOffset)
Encrypt part of the input array and stores the result in the given output array.

Note that the input must be a multiple of the block size bytes long.

Parameters:
input - array of data to encrypt
inputOffset - start of data to encrypt
inputLen - length of data to encrypt
output - array in which output is stored. This array must have room for at least getOutputSize(inputLen) bytes
outputOffset - Start offset in the output array where the output should be stored.
Returns:
the number of bytes store in the output array

getAlgorithm

public final java.lang.String getAlgorithm()
Get the name of the algorithm implemented by this Cipher instance.

Returns:
algorithm name

getBlockSize

public final int getBlockSize()
Get how big blocks this algorithm works on.

Returns:
the block size (in bytes)

getInstance

public static final Cipher getInstance(java.lang.String transformation)
                                throws NoSuchAlgorithmException
Get a Cipher instance which implements the given algorithm in any of the registered providers.

Parameters:
transformation - name of the desired algorithm (like AES/CBC).
Returns:
a Cipher instance implementing the algorithm
Throws:
NoSuchAlgorithmException - if no implementation can be found

getInstance

public static final Cipher getInstance(java.lang.String transformation,
                                       java.lang.String provider)
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException
Get a Cipher instance which implements the given algorithm in the given provider.

Parameters:
transformation - name of the desired algorithm (like AES/CBC).
Returns:
a Cipher instance implementing the algorithm
Throws:
NoSuchAlgorithmException - if no implementation can be found
NoSuchProviderException

getIV

public final byte[] getIV()
Get the IV used by this instance


getOutputSize

public final int getOutputSize(int inputLen)
Calculate how much encryted data an imput of the given length will cause.

Parameters:
inputLen - length of input data
Returns:
number of bytes output

getProvider

public final Provider getProvider()
Get the provider which implements this algorithm.


init

public final void init(int opmode,
                       Key key)
                throws InvalidKeyException
Initialize this Cipher instance.

Parameters:
opmode - The operating mode. This should be either Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE.
key - the encryption or decryption key
Throws:
InvalidKeyException

init

public final void init(int opmode,
                       Key key,
                       AlgorithmParameterSpec params)
                throws InvalidKeyException
Initialize this Cipher instance.

Parameters:
opmode - The operating mode. This should be either Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE.
key - the encryption or decryption key
params - Extra algorithm parameters
Throws:
InvalidKeyException