|
18 | 18 |
|
19 | 19 | import org.bouncycastle.crypto.BufferedBlockCipher;
|
20 | 20 | import org.bouncycastle.crypto.InvalidCipherTextException;
|
| 21 | +import org.bouncycastle.crypto.engines.AESEngine; |
21 | 22 | import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
22 | 23 | import org.bouncycastle.crypto.paddings.PKCS7Padding;
|
23 | 24 | import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
@@ -45,23 +46,21 @@ public BouncyCastleAesCbcBytesEncryptor(String password, CharSequence salt, Byte
|
45 | 46 | }
|
46 | 47 |
|
47 | 48 | @Override
|
48 |
| - @SuppressWarnings("deprecation") |
49 | 49 | public byte[] encrypt(byte[] bytes) {
|
50 | 50 | byte[] iv = this.ivGenerator.generateKey();
|
51 | 51 | PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(
|
52 |
| - new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); |
| 52 | + CBCBlockCipher.newInstance(AESEngine.newInstance()), new PKCS7Padding()); |
53 | 53 | blockCipher.init(true, new ParametersWithIV(this.secretKey, iv));
|
54 | 54 | byte[] encrypted = process(blockCipher, bytes);
|
55 | 55 | return (iv != null) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
56 | 56 | }
|
57 | 57 |
|
58 | 58 | @Override
|
59 |
| - @SuppressWarnings("deprecation") |
60 | 59 | public byte[] decrypt(byte[] encryptedBytes) {
|
61 | 60 | byte[] iv = EncodingUtils.subArray(encryptedBytes, 0, this.ivGenerator.getKeyLength());
|
62 | 61 | encryptedBytes = EncodingUtils.subArray(encryptedBytes, this.ivGenerator.getKeyLength(), encryptedBytes.length);
|
63 | 62 | PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(
|
64 |
| - new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); |
| 63 | + CBCBlockCipher.newInstance(AESEngine.newInstance()), new PKCS7Padding()); |
65 | 64 | blockCipher.init(false, new ParametersWithIV(this.secretKey, iv));
|
66 | 65 | return process(blockCipher, encryptedBytes);
|
67 | 66 | }
|
|
0 commit comments