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

public Class CFBBlockCipher

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

implements a Cipher-FeedBack (CFB) mode on top of a simple cipher.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
CFBBlockCipher(BlockCipher
the block cipher to be used as the basis of the feedback mode.
cipher
,
int
the block size in bits (note: a multiple of 8)
bitBlockSize
)

Deprecated use the equivalent CFBBlockCipher.newInstance() static method.
Basic constructor.

Method Summary

Modifier and TypeMethod and Description
protected byte
public 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 encrypted data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Do the appropriate processing for CFB mode decryption.

private byte
decryptByte(byte in)

public 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 processing for CFB mode encryption.

private byte
encryptByte(byte in)

public String

Returns:

the name of the underlying algorithm followed by "/CFB" and the block size in bits.
getAlgorithmName
()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName, org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

return the algorithm name and mode.
public int

Returns:

the block size we are operating at (in bytes).
getBlockSize
()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size we are operating at.
public byte[]

Returns:

current IV
getCurrentIV
()

Return the current state of the initialisation vector.

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, org.bouncycastle.crypto.StreamCipher.init.

Initialise the cipher and, possibly, the initialisation vector (IV).
public static CFBModeCipher
newInstance(BlockCipher
the base cipher for the CFB mode.
cipher
,
int
the block size (in bits) used for the CFB mode.
blockSize
)

Return a new CFB 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, org.bouncycastle.crypto.StreamCipher.reset.

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

Field Detail

blockSizeback to summary
private int blockSize
byteCountback to summary
private int byteCount
cfbOutVback to summary
private byte[] cfbOutV
cfbVback to summary
private byte[] cfbV
cipherback to summary
private BlockCipher cipher

Hides org.bouncycastle.crypto.StreamBlockCipher.cipher.

encryptingback to summary
private boolean encrypting
inBufback to summary
private byte[] inBuf
IVback to summary
private byte[] IV

Constructor Detail

CFBBlockCipherback to summary
public CFBBlockCipher(BlockCipher cipher, int bitBlockSize)

Deprecated

use the equivalent CFBBlockCipher.newInstance() static method.

Basic constructor.

Parameters
cipher:BlockCipher

the block cipher to be used as the basis of the feedback mode.

bitBlockSize:int

the block size in bits (note: a multiple of 8)

Method Detail

calculateByteback to summary
protected byte calculateByte(byte in) throws DataLengthException, IllegalStateException

Implements abstract org.bouncycastle.crypto.StreamBlockCipher.calculateByte.

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

Do the appropriate processing for CFB 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 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.
decryptByteback to summary
private byte decryptByte(byte in)
encryptBlockback to summary
public int encryptBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException

Do the appropriate processing for CFB 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.
encryptByteback to summary
private byte encryptByte(byte in)
getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName, org.bouncycastle.crypto.StreamCipher.getAlgorithmName.

return the algorithm name and mode.

Returns:String

the name of the underlying algorithm followed by "/CFB" and the block size in bits.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

return the block size we are operating at.

Returns:int

the block size we are operating at (in bytes).

getCurrentIVback to summary
public byte[] getCurrentIV()

Return the current state of the initialisation vector.

Returns:byte[]

current IV

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

Implements org.bouncycastle.crypto.BlockCipher.init, org.bouncycastle.crypto.StreamCipher.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. An IV which is too short is handled in FIPS compliant fashion.

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 CFBModeCipher newInstance(BlockCipher cipher, int blockSize)

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

Parameters
cipher:BlockCipher

the base cipher for the CFB mode.

blockSize:int

the block size (in bits) used for the CFB 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, org.bouncycastle.crypto.StreamCipher.reset.

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