FileDocCategorySizeDatePackage
AES_CBC.javaAPI DocphoneME MR2 API (J2ME)4999Wed May 02 18:00:00 BST 2007com.sun.midp.crypto

AES_CBC

public class AES_CBC extends AES_ECB
AES CBC Cipher.

Fields Summary
private byte[]
scratchPad
Internal buffer.
private byte[]
savedState
Saved internal buffer.
Constructors Summary
public AES_CBC()
Constructor.

        super();
        scratchPad = new byte[BLOCK_SIZE];
    
Methods Summary
public intdoFinal(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.

param
inBuff the input buffer
param
inOffset the offset in input where the input starts
param
inLength the input length
param
outBuff the buffer for the result
param
outOffset the offset in output where the result is stored
return
the number of bytes stored in output
exception
IllegalStateException if this cipher is in a wrong state (e.g., has not been initialized)
exception
javax.crypto.IllegalBlockSizeException if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size
exception
javax.crypto.ShortBufferException if the given output buffer is too small to hold the result
exception
javax.crypto.BadPaddingException if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes

        int result = super.doFinal(inBuff, inOffset, inLength,
                        outBuff, outOffset);
        System.arraycopy(IV, 0, state, 0, BLOCK_SIZE);
        return result;
    
public voidinit(int mode, Key key, CryptoParameter params)
Initializes this cipher with a key and a set of algorithm parameters.

param
mode the operation mode of this cipher
param
key the encryption key
param
params the algorithm parameters
exception
java.security.InvalidKeyException if the given key is inappropriate for initializing this cipher
exception
java.security.InvalidAlgorithmParameterException if the given algorithm parameters are inappropriate for this cipher

        doInit(mode, "AES", key, true, params);
        System.arraycopy(IV, 0, state, 0, BLOCK_SIZE);
    
protected voidprocessBlock(byte[] out, int offset)
Depending on the mode, either encrypts or decrypts one block.

param
out will contain the result of encryption or decryption operation
param
offset is the offset in out


        if (mode == Cipher.ENCRYPT_MODE)  {
            Util.xorArrays(holdData, state);
            cipherBlock();
            System.arraycopy(state, 0, out, offset, BLOCK_SIZE);
        } else {
            System.arraycopy(state, 0, scratchPad, 0, BLOCK_SIZE);
            decipherBlock();
            Util.xorArrays(state, scratchPad);
            System.arraycopy(state, 0, out, offset, BLOCK_SIZE);
            System.arraycopy(holdData, 0, state, 0, BLOCK_SIZE);
        }
        holdCount = 0;
    
protected voidrestoreState()
Restores internal state.

        super.restoreState();
        state = savedState;
    
protected voidsaveState()
Saves internal state.

        super.saveState();
        savedState = Util.cloneArray(state);