javax.crypto.AEADBadTagException: Tag mismatch!
at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:578)
at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1116)
at com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1053)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:853)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2164)
at com.kplocker.mobile.test.AesGcmExample.aesgcmDecrypt(AesGcmExample.java:27)
at com.kplocker.mobile.test.AesGcmExample.main(AesGcmExample.java:52)
如题,按照官方的文档执行也是这样,所有参数都有了,包括APIv3秘钥,依然报错
调用的URL是:https://api.mch.weixin.qq.com/risk/getcertficates
代码:
private static String aesgcmDecrypt(String aad, String iv, String cipherText) throws Exception {
final Cipher cipher = Cipher.getInstance(ALGORITHM, "SunJCE");
SecretKeySpec key = new SecretKeySpec(AES_KEY.getBytes("UTF-8"), "AES");
GCMParameterSpec spec = new GCMParameterSpec(TAG_LENGTH_BIT, iv.getBytes(), 0, iv.length());
cipher.init(Cipher.DECRYPT_MODE, key, spec);
cipher.updateAAD(aad.getBytes());
return new String(cipher.doFinal(Base64.getDecoder().decode(cipherText)));
}
请问问题解决了吗
你好,参看文档解密示例https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=19_11