1818
1919import javax .crypto .Cipher ;
2020import javax .crypto .NoSuchPaddingException ;
21- import javax .crypto .spec .IvParameterSpec ;
21+ import javax .crypto .spec .GCMParameterSpec ;
2222import javax .crypto .spec .SecretKeySpec ;
2323
2424import java .security .InvalidAlgorithmParameterException ;
2525import java .security .InvalidKeyException ;
2626import java .security .NoSuchAlgorithmException ;
27- import java .security .NoSuchProviderException ;
2827import java .security .SecureRandom ;
29- import java .security .Security ;
3028import java .util .Random ;
3129
32- import org .bouncycastle .jce .provider .BouncyCastleProvider ;
33-
3430public class AesKeyAware {
3531 protected static int ivSize ;
3632 protected static SecretKeySpec secretKey ;
3733 protected static byte [] aad ;
3834
39- static {
40- Security .addProvider (new BouncyCastleProvider ());
41- }
42-
4335 static void initCrypto () {
4436 // These are tests, we don't need a secure source of randomness.
4537 final Random random = new Random ();
@@ -69,7 +61,7 @@ protected static Cipher decryptionCipherSupplier(final byte[] encryptedChunk) {
6961 try {
7062 final Cipher encryptCipher = getCipher ();
7163 encryptCipher .init (Cipher .DECRYPT_MODE , secretKey ,
72- new IvParameterSpec ( encryptedChunk , 0 , ivSize ),
64+ new GCMParameterSpec ( 128 , encryptedChunk , 0 , ivSize ),
7365 SecureRandom .getInstanceStrong ());
7466 encryptCipher .updateAAD (aad );
7567 return encryptCipher ;
@@ -80,8 +72,8 @@ protected static Cipher decryptionCipherSupplier(final byte[] encryptedChunk) {
8072
8173 protected static Cipher getCipher () {
8274 try {
83- return Cipher .getInstance ("AES/GCM/NoPadding" , "BC" );
84- } catch (final NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e ) {
75+ return Cipher .getInstance ("AES/GCM/NoPadding" );
76+ } catch (final NoSuchAlgorithmException | NoSuchPaddingException e ) {
8577 throw new RuntimeException (e );
8678 }
8779 }
0 commit comments