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

public Class PaddedBufferedBlockCipher

extends DefaultBufferedBlockCipher
Class Inheritance
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .DataLengthException, .DefaultBufferedBlockCipher, .InvalidCipherTextException, .OutputLengthException, org.bouncycastle.crypto.params.ParametersWithRandom

A wrapper class that allows block ciphers to be used to process data in a piecemeal fashion with padding. The PaddedBufferedBlockCipher outputs a block only when the buffer is full and more data is being added, or on a doFinal (unless the current block in the buffer is a pad block). The default padding mechanism used is the one outlined in PKCS5/PKCS7.

Field Summary

Modifier and TypeField and Description
pack-priv BlockCipherPadding
Inherited from org.bouncycastle.crypto.DefaultBufferedBlockCipher:
bufbufOffcipherforEncryptionmbCipherpartialBlockOkaypgpCFB

Constructor Summary

AccessConstructor and Description
public
PaddedBufferedBlockCipher(BlockCipher
the underlying block cipher this buffering object wraps.
cipher
,
BlockCipherPadding
the padding type.
padding
)

Create a buffered block cipher with the desired padding.

public
PaddedBufferedBlockCipher(BlockCipher
the underlying block cipher this buffering object wraps.
cipher
)

Create a buffered block cipher PKCS7 padding

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of output bytes copied to out.
doFinal
(byte[]
the array the block currently being held is copied into.
out
,
int
the offset at which the copying starts.
outOff
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.doFinal.

Process the last block in the buffer.

public int

Returns:

the space required to accommodate a call to update and doFinal with len bytes of input.
getOutputSize
(int
the length of the input.
len
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.getOutputSize.

return the minimum size of the output buffer required for an update plus a doFinal with an input of len bytes.

public int

Returns:

the space required to accommodate a call to update with len bytes of input.
getUpdateOutputSize
(int
the length of the input.
len
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.getUpdateOutputSize.

return the size of the output buffer required for an update an input of len bytes.

public void
init(boolean
if true the cipher is initialised for encryption, if false for decryption.
forEncryption
,
CipherParameters
the key and other data required by the cipher.
params
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.init.

initialise the cipher.

public int

Returns:

the number of output bytes copied to out.
processByte
(byte
the input byte.
in
,
byte[]
the space for any output that might be produced.
out
,
int
the offset from which the output will be copied.
outOff
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.processByte.

process a single byte, producing an output block if neccessary.

public int

Returns:

the number of output bytes copied to out.
processBytes
(byte[]
the input byte array.
in
,
int
the offset at which the input data starts.
inOff
,
int
the number of bytes to be copied out of the input array.
len
,
byte[]
the space for any output that might be produced.
out
,
int
the offset from which the output will be copied.
outOff
)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.processBytes.

process an array of bytes, producing output if necessary.

Inherited from org.bouncycastle.crypto.DefaultBufferedBlockCipher:
getBlockSizegetUnderlyingCipherreset

Field Detail

paddingback to summary
pack-priv BlockCipherPadding padding

Constructor Detail

PaddedBufferedBlockCipherback to summary
public PaddedBufferedBlockCipher(BlockCipher cipher, BlockCipherPadding padding)

Create a buffered block cipher with the desired padding.

Parameters
cipher:BlockCipher

the underlying block cipher this buffering object wraps.

padding:BlockCipherPadding

the padding type.

PaddedBufferedBlockCipherback to summary
public PaddedBufferedBlockCipher(BlockCipher cipher)

Create a buffered block cipher PKCS7 padding

Parameters
cipher:BlockCipher

the underlying block cipher this buffering object wraps.

Method Detail

doFinalback to summary
public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException, InvalidCipherTextException

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.doFinal.

Process the last block in the buffer. If the buffer is currently full and padding needs to be added a call to doFinal will produce 2 * getBlockSize() bytes.

Parameters
out:byte[]

the array the block currently being held is copied into.

outOff:int

the offset at which the copying starts.

Returns:int

the number of output bytes copied to out.

Exceptions
DataLengthException:
if there is insufficient space in out for the output or we are decrypting and the input is not block size aligned.
IllegalStateException:
if the underlying cipher is not initialised.
InvalidCipherTextException:
if padding is expected and not found.
getOutputSizeback to summary
public int getOutputSize(int len)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.getOutputSize.

return the minimum size of the output buffer required for an update plus a doFinal with an input of len bytes.

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to update and doFinal with len bytes of input.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.getUpdateOutputSize.

return the size of the output buffer required for an update an input of len bytes.

Parameters
len:int

the length of the input.

Returns:int

the space required to accommodate a call to update with len bytes of input.

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

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.init.

initialise the cipher.

Parameters
forEncryption: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.
processByteback to summary
public int processByte(byte in, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.processByte.

process a single byte, producing an output block if neccessary.

Parameters
in:byte

the input byte.

out:byte[]

the space for any output that might be produced.

outOff:int

the offset from which the output will be copied.

Returns:int

the number of output bytes copied to out.

Exceptions
DataLengthException:
if there isn't enough space in out.
IllegalStateException:
if the cipher isn't initialised.
processBytesback to summary
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Overrides org.bouncycastle.crypto.DefaultBufferedBlockCipher.processBytes.

process an array of bytes, producing output if necessary.

Parameters
in:byte[]

the input byte array.

inOff:int

the offset at which the input data starts.

len:int

the number of bytes to be copied out of the input array.

out:byte[]

the space for any output that might be produced.

outOff:int

the offset from which the output will be copied.

Returns:int

the number of output bytes copied to out.

Exceptions
DataLengthException:
if there isn't enough space in out.
IllegalStateException:
if the cipher isn't initialised.