Top Description Fields Constructors Methods
org.bouncycastle.crypto

public Class BufferedBlockCipher

extends Object
Class Inheritance
Known Direct Subclasses
org.bouncycastle.crypto.DefaultBufferedBlockCipher

A wrapper class that allows block ciphers to be used to process data in a piecemeal fashion. The BufferedBlockCipher outputs a block only when the buffer is full and more data is being added, or on a doFinal.

Note

in the case where the underlying cipher is either a CFB cipher or an OFB one the last block may not be a multiple of the block size.

Field Summary

Modifier and TypeField and Description
protected byte[]
protected int
protected BlockCipher
protected boolean
protected MultiBlockCipher
protected boolean
protected boolean

Constructor Summary

AccessConstructor and Description
pack-priv
BufferedBlockCipher()

constructor for subclasses

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

Deprecated use the constructor on DefaultBufferedBlockCipher.
Create a buffered block cipher without 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
)

Process the last block in the buffer.

public int

Returns:

the blocksize for the underlying cipher.
getBlockSize
()

return the blocksize for the underlying cipher.

public int

Returns:

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

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

public BlockCipher

Returns:

the cipher this object wraps.
getUnderlyingCipher
()

return the cipher this object wraps.

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
)

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
)

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
)

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

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
)

process an array of bytes, producing output if necessary.

public void
reset()

Reset the buffer and cipher.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
protected byte[] buf
bufOffback to summary
protected int bufOff
cipherback to summary
protected BlockCipher cipher
forEncryptionback to summary
protected boolean forEncryption
mbCipherback to summary
protected MultiBlockCipher mbCipher
partialBlockOkayback to summary
protected boolean partialBlockOkay
pgpCFBback to summary
protected boolean pgpCFB

Constructor Detail

BufferedBlockCipherback to summary
pack-priv BufferedBlockCipher()

constructor for subclasses

BufferedBlockCipherback to summary
public BufferedBlockCipher(BlockCipher cipher)

Deprecated

use the constructor on DefaultBufferedBlockCipher.

Create a buffered block cipher without 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

Process the last block in the buffer.

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 the input is not block size aligned and should be.
  • if the input is not block size aligned.
IllegalStateException:
if the underlying cipher is not initialised.
InvalidCipherTextException:
if padding is expected and not found.
getBlockSizeback to summary
public int getBlockSize()

return the blocksize for the underlying cipher.

Returns:int

the blocksize for the underlying cipher.

getOutputSizeback to summary
public int getOutputSize(int length)

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

Parameters
length:int

the length of the input.

Returns:int

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

getUnderlyingCipherback to summary
public BlockCipher getUnderlyingCipher()

return the cipher this object wraps.

Returns:BlockCipher

the cipher this object wraps.

getUpdateOutputSizeback to summary
public int getUpdateOutputSize(int len)

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

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

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

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

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.
resetback to summary
public void reset()

Reset the buffer and cipher. After resetting the object is in the same state as it was after the last init (if there was one).