66import javax .crypto .Cipher ;
77import javax .crypto .spec .IvParameterSpec ;
88import javax .crypto .spec .SecretKeySpec ;
9- import java .nio .ByteBuffer ;
109import java .nio .charset .Charset ;
1110import java .nio .charset .StandardCharsets ;
1211import java .security .GeneralSecurityException ;
@@ -82,10 +81,7 @@ private static Key generateKeyFromString(byte[] keyVal) {
8281 public static byte [] encrypt (byte [] signer , byte [] derivedKey ) {
8382 try {
8483 Key key = generateKeyFromString (derivedKey );
85- byte [] nonce = ByteBuffer .allocate (8 ).putLong (0 ).array ();
86- byte [] iv = new byte [16 ];
87- System .arraycopy (nonce , 0 , iv , 0 , nonce .length );
88- IvParameterSpec ivSpec = new IvParameterSpec (iv );
84+ IvParameterSpec ivSpec = new IvParameterSpec (new byte [16 ]);
8985 Cipher c = Cipher .getInstance (CIPHER );
9086 c .init (Cipher .ENCRYPT_MODE , key , ivSpec );
9187 return c .doFinal (signer );
@@ -98,10 +94,7 @@ public static byte[] encrypt(byte[] signer, byte[] derivedKey) {
9894 public static byte [] decrypt (byte [] signer , byte [] derivedKey ) {
9995 try {
10096 Key key = generateKeyFromString (derivedKey );
101- byte [] nonce = ByteBuffer .allocate (8 ).putLong (0 ).array ();
102- byte [] iv = new byte [16 ];
103- System .arraycopy (nonce , 0 , iv , 0 , nonce .length );
104- IvParameterSpec ivSpec = new IvParameterSpec (iv );
97+ IvParameterSpec ivSpec = new IvParameterSpec (new byte [16 ]);
10598 Cipher c = Cipher .getInstance (CIPHER );
10699 c .init (Cipher .DECRYPT_MODE , key , ivSpec );
107100 return c .doFinal (signer );
0 commit comments