Cumulus4j API
(1.1.0)

org.cumulus4j.crypto
Class AbstractCipher

java.lang.Object
  extended by org.cumulus4j.crypto.AbstractCipher
All Implemented Interfaces:
Cipher
Direct Known Subclasses:
AEADBlockCipherImpl, AsymmetricBlockCipherImpl, BufferedBlockCipherImpl, StreamCipherImpl

public abstract class AbstractCipher
extends Object
implements Cipher

Abstract base class for Cipher implementations. Implementors should not implement the Cipher interface directly, but sub-class this class instead.

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Constructor Summary
protected AbstractCipher(String transformation)
           
 
Method Summary
protected abstract  void _init(CipherOperationMode mode, CipherParameters parameters)
           
 byte[] doFinal(byte[] in)
          Convenience method to encrypt/decrypt the complete input byte array at once.
 CipherOperationMode getMode()
          Get the mode of this cipher.
 CipherParameters getParameters()
          Get the parameters of this cipher.
 String getTransformation()
          Get the transformation that was passed to CryptoRegistry.createCipher(String) for obtaining this Cipher.
 void init(CipherOperationMode mode, CipherParameters parameters)
           Initialise the cipher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.cumulus4j.crypto.Cipher
doFinal, getInputBlockSize, getIVSize, getOutputBlockSize, getOutputSize, getUpdateOutputSize, reset, update, update
 

Constructor Detail

AbstractCipher

protected AbstractCipher(String transformation)
Method Detail

getTransformation

public final String getTransformation()
Description copied from interface: Cipher
Get the transformation that was passed to CryptoRegistry.createCipher(String) for obtaining this Cipher.

Specified by:
getTransformation in interface Cipher
Returns:
the transformation (encryption algorithm, mode and padding) of this cipher.

doFinal

public byte[] doFinal(byte[] in)
               throws DataLengthException,
                      IllegalStateException,
                      CryptoException
Description copied from interface: Cipher
Convenience method to encrypt/decrypt the complete input byte array at once. After this method was called, no unprocessed data is left in this cipher and it is Cipher.reset() implicitly.

Specified by:
doFinal in interface Cipher
Parameters:
in - the input to be encrypted or decrypted. Must not be null.
Returns:
the processed output.
Throws:
IllegalStateException - if the cipher isn't initialised.
CryptoException - if padding is expected and not found or sth. else goes wrong while encrypting or decrypting.
DataLengthException

init

public final void init(CipherOperationMode mode,
                       CipherParameters parameters)
                throws IllegalArgumentException
Description copied from interface: Cipher

Initialise the cipher.

A cipher cannot be used, before this method was called.

A cipher can be re-initialised to modify only certain parameters (and keep the others). For example to modify the IV while keeping the key, a cipher can be re-initialised with an IV only (i.e. null is passed to ParametersWithIV.ParametersWithIV(CipherParameters, byte[], int, int) instead of a KeyParameter). This is useful for performance reasons, because modifying an IV is a very fast operation while changing the key is slow (especially Blowfish is known for its very slow key initialisation).

Specified by:
init in interface Cipher
Parameters:
mode - the operation mode; must not be null.
parameters - the parameters; for example an instance of ParametersWithIV with a wrapped KeyParameter to pass IV and secret key.
Throws:
IllegalArgumentException - if the given arguments are invalid - for example if the given parameters are not understood by the implementation (parameters not compatible with the chosen algorithm).

getMode

public CipherOperationMode getMode()
Description copied from interface: Cipher
Get the mode of this cipher. This is null, before Cipher.init(CipherOperationMode, CipherParameters) was called the first time.

Specified by:
getMode in interface Cipher
Returns:
the mode of this cipher.

getParameters

public CipherParameters getParameters()
Description copied from interface: Cipher
Get the parameters of this cipher. This is null, before Cipher.init(CipherOperationMode, CipherParameters) was called the first time.

Specified by:
getParameters in interface Cipher
Returns:
the parameters of this cipher.

_init

protected abstract void _init(CipherOperationMode mode,
                              CipherParameters parameters)
                       throws IllegalArgumentException
Throws:
IllegalArgumentException

Cumulus4j API
(1.1.0)

Copyright © 2013 NightLabs Consulting GmbH. All Rights Reserved.