The encrypted content gAAA...-Q== could not be verified. Reason: Encrypted conte...
错误信息
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:The encrypted content gAAA...-Q== could not be verified. Reason: Encrypted content could not be decrypted or parsed.
译文:加密内容 gAAA...-Q== 无法被验证。原因:加密内容无法被解密或解析。
2. 🎯 原因分析
3. 💡 解决方案
修复步骤:
== 或 =,且长度为 4 的倍数)``代码语言
// 示例:AES-GCM 解密(需确保密钥、IV 与加密端一致)
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class Decryptor {
private static final int AES_KEY_SIZE = 128;
private static final int GCM_IV_LENGTH = 12;
public static String decrypt(String encryptedData, String key, String iv) throws Exception {
byte[] keyBytes = key.getBytes();
byte[] ivBytes = iv.getBytes();
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData);
// 提取密文(前12字节为IV,后续为密文+认证标签)
byte[] actualIv = new byte[GCM_IV_LENGTH];
System.arraycopy(encryptedBytes, 0, actualIv, 0, GCM_IV_LENGTH);
byte[] cipherTextAndTag = new byte[encryptedBytes.length - GCM_IV_LENGTH];
System.arraycopy(encryptedBytes, GCM_IV_LENGTH, cipherTextAndTag, 0, cipherTextAndTag.length);
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
GCMParameterSpec gcmSpec = new GCMParameterSpec(128, actualIv);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, secretKey, gcmSpec);
byte[] decryptedBytes = cipher.doFinal(cipherTextAndTag);
return new String(decryptedBytes);
}
}
``