Search in sources :

Example 6 with PKCS7Padding

use of org.bouncycastle.crypto.paddings.PKCS7Padding in project spring-security by spring-projects.

the class BouncyCastleAesCbcBytesEncryptor method encrypt.

@Override
@SuppressWarnings("deprecation")
public byte[] encrypt(byte[] bytes) {
    byte[] iv = this.ivGenerator.generateKey();
    PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding());
    blockCipher.init(true, new ParametersWithIV(this.secretKey, iv));
    byte[] encrypted = process(blockCipher, bytes);
    return (iv != null) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV) PaddedBufferedBlockCipher(org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher) PKCS7Padding(org.bouncycastle.crypto.paddings.PKCS7Padding) CBCBlockCipher(org.bouncycastle.crypto.modes.CBCBlockCipher)

Aggregations

CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)6 PKCS7Padding (org.bouncycastle.crypto.paddings.PKCS7Padding)6 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)6 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)6 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)4 AESEngine (org.bouncycastle.crypto.engines.AESEngine)4 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)4 CipherParameters (org.bouncycastle.crypto.CipherParameters)2 DataLengthException (org.bouncycastle.crypto.DataLengthException)2 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)2 BlockCipherPadding (org.bouncycastle.crypto.paddings.BlockCipherPadding)1