Search in sources :

Example 41 with ParametersWithRandom

use of org.bouncycastle.crypto.params.ParametersWithRandom in project keepass2android by PhilippC.

the class PaddedBufferedBlockCipher method init.

/**
 * initialise the cipher.
 *
 * @param forEncryption if true the cipher is initialised for
 *  encryption, if false for decryption.
 * @param params the key and other data required by the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException {
    this.forEncryption = forEncryption;
    reset();
    if (params instanceof ParametersWithRandom) {
        ParametersWithRandom p = (ParametersWithRandom) params;
        padding.init(p.getRandom());
        cipher.init(forEncryption, p.getParameters());
    } else {
        padding.init(null);
        cipher.init(forEncryption, params);
    }
}
Also used : ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom)

Aggregations

ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)41 SecureRandom (java.security.SecureRandom)20 CipherParameters (org.bouncycastle.crypto.CipherParameters)12 AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)8 InvalidKeyException (java.security.InvalidKeyException)7 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 InvalidParameterException (java.security.InvalidParameterException)5 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)5 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)5 ParametersWithID (org.bouncycastle.crypto.params.ParametersWithID)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 BadPaddingException (javax.crypto.BadPaddingException)3 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 SecretKey (javax.crypto.SecretKey)3 ShortBufferException (javax.crypto.ShortBufferException)3 IvParameterSpec (javax.crypto.spec.IvParameterSpec)3 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)3 DataLengthException (org.bouncycastle.crypto.DataLengthException)3 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)3