|
25 | 25 | import org.bouncycastle.crypto.engines.AESEngine; |
26 | 26 | import org.bouncycastle.crypto.generators.Argon2BytesGenerator; |
27 | 27 | import org.bouncycastle.crypto.modes.GCMBlockCipher; |
| 28 | +import org.bouncycastle.crypto.modes.GCMModeCipher; |
28 | 29 | import org.bouncycastle.crypto.params.AEADParameters; |
29 | 30 | import org.bouncycastle.crypto.params.Argon2Parameters; |
30 | 31 | import org.bouncycastle.crypto.params.KeyParameter; |
@@ -83,7 +84,7 @@ private static byte[] generateKey(byte[] password, byte[] salt) { |
83 | 84 | */ |
84 | 85 | private static byte[] generateAdditionalData(byte[] key, byte[] paddedNonce) |
85 | 86 | throws InvalidCipherTextException { |
86 | | - GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine()); |
| 87 | + GCMModeCipher cipher = GCMBlockCipher.newInstance(AESEngine.newInstance()); |
87 | 88 | cipher.init(true, new AEADParameters(new KeyParameter(key), 128, paddedNonce)); |
88 | 89 | int outputLength = cipher.getMac().length; |
89 | 90 | byte[] additionalData = new byte[outputLength]; |
@@ -132,7 +133,7 @@ public static byte[] encrypt(String password, byte[] data) |
132 | 133 | /** Increment IV (nonce) by 1 as we used it for generating a tag for additional data. */ |
133 | 134 | paddedNonce[8] = 1; |
134 | 135 |
|
135 | | - GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine()); |
| 136 | + GCMModeCipher cipher = GCMBlockCipher.newInstance(AESEngine.newInstance()); |
136 | 137 | cipher.init(true, new AEADParameters(new KeyParameter(key), 128, paddedNonce, additionalData)); |
137 | 138 | int outputLength = cipher.getOutputSize(data.length); |
138 | 139 | byte[] encryptedData = new byte[outputLength]; |
@@ -180,7 +181,7 @@ public static byte[] decrypt(String password, byte[] payload) |
180 | 181 | /** Increment IV (nonce) by 1 as we used it for generating a tag for additional data. */ |
181 | 182 | paddedNonce[8] = 1; |
182 | 183 |
|
183 | | - GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine()); |
| 184 | + GCMModeCipher cipher = GCMBlockCipher.newInstance(AESEngine.newInstance()); |
184 | 185 | cipher.init(false, new AEADParameters(new KeyParameter(key), 128, paddedNonce, additionalData)); |
185 | 186 | int outputLength = cipher.getOutputSize(encryptedData.length); |
186 | 187 | byte[] decryptedData = new byte[outputLength]; |
|
0 commit comments