Skip to content

Commit

Permalink
Update AESCBC.java
Browse files Browse the repository at this point in the history
Fixing error, removing IV
  • Loading branch information
tomcrofts authored Jun 6, 2024
1 parent ad4cb12 commit b55f020
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mastercard.developer.utils.EncodingUtils;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.GeneralSecurityException;
Expand All @@ -24,14 +23,13 @@ public static byte[] decrypt(Key secretKey, JweObject object) throws GeneralSecu
SecretKeySpec aesKey = new SecretKeySpec(secretKey.getEncoded(), 16, 16, "AES");
GCMParameterSpec gcmSpec = new GCMParameterSpec(128, EncodingUtils.base64Decode(object.getIv()));
byte[] cipherText = EncodingUtils.base64Decode(object.getCipherText());
byte[] iv = EncodingUtils.base64Decode(object.getIv());

return cipher(aesKey, gcmSpec, new IvParameterSpec(iv), cipherText, Cipher.DECRYPT_MODE);
return cipher(aesKey, gcmSpec, cipherText, Cipher.DECRYPT_MODE);
}

public static byte[] cipher(Key key,GCMParameterSpec gcpSpec, AlgorithmParameterSpec iv, byte[] bytes, int mode) throws GeneralSecurityException {
public static byte[] cipher(Key key,GCMParameterSpec gcpSpec, byte[] bytes, int mode) throws GeneralSecurityException {
Cipher cipher = Cipher.getInstance(CYPHER);
cipher.init(mode, key, gcpSpec, iv);
cipher.init(mode, key, gcpSpec);
return cipher.doFinal(bytes);
}
}

0 comments on commit b55f020

Please sign in to comment.