Example usage for org.bouncycastle.crypto.modes CBCBlockCipher CBCBlockCipher

List of usage examples for org.bouncycastle.crypto.modes CBCBlockCipher CBCBlockCipher

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.modes CBCBlockCipher CBCBlockCipher.

Prototype

public CBCBlockCipher(BlockCipher cipher) 

Source Link

Document

Basic constructor.

Usage

From source file:secret.sharing.Encryptor.java

License:Open Source License

/**
 * Initiate the block cipher//from  ww  w.  j  a v  a  2s .  co  m
 * @param passphrase string used for encryption / decryption and authentification
 * @param encryptionSalt encryption salt for encrytption / decryption key
 * @param initVector initialization vector for CBC mode
 * @param mode True = encrypt; False = decrypt
 */
private void initCipher(String passphrase, byte[] encryptionSalt, byte[] initVector, boolean mode)
        throws NoSuchAlgorithmException, InvalidKeySpecException {
    CBCBlockCipher cbcBlockCipher = new CBCBlockCipher(new AESFastEngine());
    mCipher = new BufferedBlockCipher(cbcBlockCipher);
    byte[] encryptionKey = deriveKey(passphrase, encryptionSalt, mEncryptionKeySize);
    ParametersWithIV parameters = new ParametersWithIV(new KeyParameter(encryptionKey), initVector);
    mCipher.init(mode, parameters);
}