I have some AES/GCM encrypted data and wanted to decrypt it. I want to decrypt it bypassing authentication as the data does not contain authentication information(Data is encrypted by a third party application). I tried decryption with javax.crypto package and it is always throwing tag mismatch error. Is there any way to bypass this tag checking and decrypt data. Data is encrypted with AES128 and it is using 12 byte initialization vector.
Edit: I got a temporary solution for this issue. Not sure if this is correct method.
Key key = new SecretKeySpec(hlsKey, "AES");
GCMParameterSpec gCMParameterSpec = new GCMParameterSpec(96, initialisationVector);
final Cipher c = Cipher.getInstance("AES/GCM/NoPadding", "BC");
c.init(Cipher.DECRYPT_MODE, key, gCMParameterSpec);
byte[] nodata = new byte[len * 2];
System.arraycopy(cipherText, 0, nodata, 0, len);
byte[] plaindata = new byte[len * 2];
try {
int decrypted_index = 0;
while (decrypted_index < len) {
int cp = c.update(nodata, decrypted_index, nodata.length - decrypted_index, plaindata, decrypted_index);//doFinal(nodata);
decrypted_index += cp;
}
if(decrypted_index>=len){
System.arraycopy(plaindata, 0, plainText, 0, len);
retvalue=1;
}
} catch (Exception e) {
e.printStackTrace();
}
c.update
does always return the plaintext data before validating the authentication tag. And that's implementation specific. It's also relatively inefficient wrt memory, but for a make-shift solution it is OK. Oh yeah, and theif(decrypted_index>=len){
test is of course bunk given the test within the while loop;decrypted_index
must be>= len
. – Maarten Bodewes