我有一些AES/GCM加密数据,想要解密它.我希望绕过身份验证解密它,因为数据不包含身份验证信息(数据由第三方应用程序加密).我尝试使用javax.crypto包进行解密,并且总是抛出标签不匹配错误.有没有办法绕过这个标签检查和解密数据.数据使用AES128加密,并使用12字节初始化向量.
编辑:我有一个临时解决方案来解决这个问题.不确定这是否是正确的方法.
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) { …Run Code Online (Sandbox Code Playgroud)