DES_CBCpublic class DES_CBC extends DES_ECB DES CBC Cipher algorithm. |
Fields Summary |
---|
private byte[] | chainingBlockInternal data. | private byte[] | storeBufferInternal data. | private byte[] | savedChainingBlockSaved state variable. |
Constructors Summary |
---|
public DES_CBC(boolean useTripleDes)Constructor.
super(useTripleDes);
chainingBlock = new byte[BLOCK_SIZE];
storeBuffer = new byte[BLOCK_SIZE];
|
Methods Summary |
---|
public int | doFinal(byte[] inBuff, int inOffset, int inLength, byte[] outBuff, int outOffset)Encrypts or decrypts data in a single-part operation, or finishes a
multiple-part operation. The data is encrypted or decrypted,
depending on how this cipher was initialized.
int result = super.doFinal(inBuff, inOffset, inLength,
outBuff, outOffset);
System.arraycopy(IV, 0, chainingBlock, 0, BLOCK_SIZE);
return result;
| public void | init(int mode, Key key, CryptoParameter params)Initializes this cipher with a key and a set of algorithm
parameters.
doInit(mode, keyAlgorithm, key, true, params);
System.arraycopy(IV, 0, chainingBlock, 0, BLOCK_SIZE);
| protected void | processBlock(byte[] out, int offset)Depending on the mode, either encrypts or decrypts data block.
if (mode == Cipher.ENCRYPT_MODE) {
Util.xorArrays(holdData, chainingBlock);
super.processBlock(out, offset);
System.arraycopy(out, offset, chainingBlock, 0, BLOCK_SIZE);
} else {
System.arraycopy(holdData, 0, storeBuffer, 0, BLOCK_SIZE);
super.processBlock(out, offset);
for (int i = 0; i < BLOCK_SIZE; i++) {
out[offset + i] ^= chainingBlock[i];
}
System.arraycopy(storeBuffer, 0, chainingBlock, 0, BLOCK_SIZE);
}
| protected void | restoreState()Restores cipher state.
super.restoreState();
chainingBlock = savedChainingBlock;
| protected void | saveState()Saves cipher state.
super.saveState();
savedChainingBlock = Util.cloneArray(chainingBlock);
|
|