All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----javax.crypto.CipherSpi
|
+----au.net.aba.crypto.provider.BlockCipher
This class supports PKCS#5 and NoPadding, as well as supporting ECB and CBC modes. The standard block size is 8.
To implement a new block cipher it is necessary to implement
the three abstract methods that re-key the cipher, do encryption
and decryption using the current. It may also be necessary
to override the engineSetMode method if CBC
or ECB are not supported. If different padding mechanisms are
used engineSetPadding may be overridden (in
which case it may also be necessary to override
engineGetOutputSize). For block sizes other than 8
engineGetBlockSize should be overridden. Finally
if the algorithm supports AlgorithmParameterSpec just override
the engineInit method that accepts those parameters.
public static final String ident
protected static final int BLOCK_SIZE
protected static final int ECB
protected static final int CBC
protected byte buffer[]
protected int bufferPos
protected int mode
protected boolean paddedStream
protected int streamMode
protected byte ivec[]
protected byte cbcV[]
protected boolean ivInline
protected boolean ivEncrypted
protected boolean firstBlock
protected Key key
protected SecureRandom random
public BlockCipher()
protected void engineSetMode(String mode) throws NoSuchAlgorithmException
protected void engineSetPadding(String padding) throws NoSuchPaddingException
protected int engineGetBlockSize()
protected int engineGetOutputSize(int inputLen)
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.
protected byte[] engineGetIV()
This is useful in the context of password-based encryption or decryption, where the IV is derived from a user-provided passphrase.
protected AlgorithmParameters engineGetParameters()
The returned parameters may be the same that were used to initialise this cipher, or may contain the default set of parameters or a set of randomly generated parameters used by the underlying cipher implementation (provided that the underlying cipher implementation uses a default set of parameters or creates new parameters if it needs parameters but was not initialised with any).
protected void engineInit(int opmode,
Key key,
SecureRandom random) throws InvalidKeyException
The cipher is initialised for encryption or decryption, depending on the value of opmode.
If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialised for encryption, and raise an InvalidKeyException if it is being initialised for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).
If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.
Note that when a Cipher object is initialised, it loses all previously-acquired state. In other words, initialising a Cipher is equivalent to creating a new instance of that Cipher and initialising it
protected void engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
The cipher is initialised for encryption or decryption, depending on the value of opmode.
If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialised for encryption, and raise an InvalidAlgorithmParameterException if it is being initialised for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).
If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.
Note that when a Cipher object is initialised, it loses all previously-acquired state. In other words, initialising a Cipher is equivalent to creating a new instance of that Cipher and initialising it.
protected void engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
The cipher is initialised for encryption or decryption, depending on the value of opmode.
If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialised for encryption, and raise an InvalidAlgorithmParameterException if it is being initialised for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).
If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.
Note that when a Cipher object is initialised, it loses all previously-acquired state. In other words, initialising a Cipher is equivalent to creating a new instance of that Cipher and initialising it.
protected byte[] engineUpdate(byte input[],
int inputOff,
int inputLen)
The first inputLen bytes in the input buffer, starting at inputOffset, are processed, and the result is stored in a new buffer.
protected int engineUpdate(byte input[],
int inputOff,
int inputLen,
byte output[],
int outputOff) throws ShortBufferException
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.
protected byte[] engineDoFinal(byte input[],
int inputOff,
int inputLen) throws IllegalBlockSizeException, BadPaddingException
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.
The cipher is reset to its initial state (uninitialised) after this call.
protected int engineDoFinal(byte input[],
int inputOff,
int inputLen,
byte output[],
int outputOff) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException
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.
protected void reset()
protected abstract void setKey(Key key) throws InvalidKeyException
protected abstract int encryptBlock(byte in[],
int inoff,
int len,
byte out[],
int outOff) throws IllegalBlockSizeException
protected abstract int decryptBlock(byte in[],
int inoff,
int len,
byte out[],
int outOff) throws BadPaddingException
All Packages Class Hierarchy This Package Previous Next Index