Top Description Fields Constructors Methods
org.bouncycastle.crypto.modes

public Class CBCBlockCipher

extends DefaultMultiBlockCipher
implements CBCModeCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.modes.CBCModeCipher, org.bouncycastle.crypto.MultiBlockCipher, org.bouncycastle.crypto.BlockCipher
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .DefaultMultiBlockCipher, org.bouncycastle.crypto.params.ParametersWithIV, org.bouncycastle.util.Arrays

implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.

Field Summary

Modifier and TypeField and Description
private int
private byte[]
private byte[]
private BlockCipher
private boolean
private byte[]

Constructor Summary

AccessConstructor and Description
public
CBCBlockCipher(BlockCipher
the block cipher to be used as the basis of chaining.
cipher
)

Deprecated use the CBCBlockCipher.newInstance() static method.
Basic constructor.

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

the number of bytes processed and produced.
decryptBlock
(byte[]
the array containing the data to be decrypted.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the decrypted data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Do the appropriate chaining step for CBC mode decryption.

private int

Returns:

the number of bytes processed and produced.
encryptBlock
(byte[]
the array containing the data to be encrypted.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the encrypted data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Do the appropriate chaining step for CBC mode encryption.

public String

Returns:

the name of the underlying algorithm followed by "/CBC".
getAlgorithmName
()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

return the algorithm name and mode.
public int

Returns:

the block size of the underlying cipher.
getBlockSize
()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size of the underlying cipher.
public BlockCipher

Returns:

the underlying block cipher that we are wrapping.
getUnderlyingCipher
()

Implements org.bouncycastle.crypto.modes.CBCModeCipher.getUnderlyingCipher.

return the underlying block cipher that we are wrapping.
public void
init(boolean
if true the cipher is initialised for encryption, if false for decryption.
encrypting
,
CipherParameters
the key and other data required by the cipher.
params
)

Implements org.bouncycastle.crypto.BlockCipher.init.

Initialise the cipher and, possibly, the initialisation vector (IV).
public static CBCModeCipher
newInstance(BlockCipher
the base cipher for the CBC mode.
cipher
)

Return a new CBC mode cipher based on the passed in base cipher

public int

Returns:

the number of bytes processed and produced.
processBlock
(byte[]
the array containing the input data.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the output data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.
public void
reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

reset the chaining vector back to the IV and reset the underlying cipher.
Inherited from org.bouncycastle.crypto.DefaultMultiBlockCipher:
getMultiBlockSizeprocessBlocks

Field Detail

blockSizeback to summary
private int blockSize
cbcNextVback to summary
private byte[] cbcNextV
cbcVback to summary
private byte[] cbcV
cipherback to summary
private BlockCipher cipher
encryptingback to summary
private boolean encrypting
IVback to summary
private byte[] IV

Constructor Detail

CBCBlockCipherback to summary
public CBCBlockCipher(BlockCipher cipher)

Deprecated

use the CBCBlockCipher.newInstance() static method.

Basic constructor.

Parameters
cipher:BlockCipher

the block cipher to be used as the basis of chaining.

Method Detail

decryptBlockback to summary
private int decryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Do the appropriate chaining step for CBC mode decryption.

Parameters
in:byte[]

the array containing the data to be decrypted.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the decrypted data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
encryptBlockback to summary
private int encryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Do the appropriate chaining step for CBC mode encryption.

Parameters
in:byte[]

the array containing the data to be encrypted.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the encrypted data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

return the algorithm name and mode.

Returns:String

the name of the underlying algorithm followed by "/CBC".

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size of the underlying cipher.

Returns:int

the block size of the underlying cipher.

getUnderlyingCipherback to summary
public BlockCipher getUnderlyingCipher()

Implements org.bouncycastle.crypto.modes.CBCModeCipher.getUnderlyingCipher.

return the underlying block cipher that we are wrapping.

Returns:BlockCipher

the underlying block cipher that we are wrapping.

initback to summary
public void init(boolean encrypting, CipherParameters params) throws IllegalArgumentException

Implements org.bouncycastle.crypto.BlockCipher.init.

Initialise the cipher and, possibly, the initialisation vector (IV). If an IV isn't passed as part of the parameter, the IV will be all zeros.

Parameters
encrypting:boolean

if true the cipher is initialised for encryption, if false for decryption.

params:CipherParameters

the key and other data required by the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
newInstanceback to summary
public static CBCModeCipher newInstance(BlockCipher cipher)

Return a new CBC mode cipher based on the passed in base cipher

Parameters
cipher:BlockCipher

the base cipher for the CBC mode.

processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.

Parameters
in:byte[]

the array containing the input data.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the output data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

Exceptions
DataLengthException:
if there isn't enough data in in, or space in out.
IllegalStateException:
if the cipher isn't initialised.
resetback to summary
public void reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

reset the chaining vector back to the IV and reset the underlying cipher.