比如用的 FastJson 库: @Test public void decryptPayCallbackContentTest() throws GeneralSecurityException, IOException { String content = "{\"id\":\"f00e26a0-d255-5bfd-8f0d-a0275df040ad\",\"create_time\":\"2021-09-30T16:08:53+08:00\",\"resource_type\":\"encrypt-resource\",\"event_type\":\"TRANSACTION.SUCCESS\",\"summary\":\"支付成功\",\"resource\":{\"original_type\":\"transaction\",\"algorithm\":\"AEAD_AES_256_GCM\",\"ciphertext\":\"lZr3KNzyREUwOpGTp8******ncWT3t1n0eU20wdk=\",\"associated_data\":\"transaction\",\"nonce\":\"cji332epFsZO\"}}"; JSONObject parseObject = JSON.parseObject(content); JSONObject resourceObject = parseObject.getJSONObject("resource"); AesUtil aesUtil = new AesUtil(apiV3Key.getBytes(StandardCharsets.UTF_8)); // 这里很重要 String transaction = resourceObject.getString("associated_data"); String nonceStr = resourceObject.getString("nonce"); String cipherText = resourceObject.getString("ciphertext"); Assertions.assertThrows(AEADBadTagException.class, () -> { // 错误的做法 aesUtil.decryptToString(resourceObject.getBytes("associated_data"), resourceObject.getBytes("nonce"), resourceObject.getString("ciphertext")); }); Assertions.assertDoesNotThrow(() -> { // 对的做法 aesUtil.decryptToString(transaction.getBytes(StandardCharsets.UTF_8), nonceStr.getBytes(StandardCharsets.UTF_8), cipherText); }); }
微信特约商户 证书解密 Tag mismatch!获取微信支付特约商户进件 加密证书用的是从服务商下载的证书apicclient_cert.pem 解密用的是获取平台证书 [图片] 解密代码 [图片] javax.crypto.AEADBadTagException: Tag mismatch! at com.sun.crypto.provider.GaloisCounterMode.decryptFinal(GaloisCounterMode.java:524) at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:1023) at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:960) at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824) at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436) at javax.crypto.Cipher.doFinal(Cipher.java:2165)
2021-09-30[图片]为了解决这个问题,把微信文档都翻了一遍,没找到详细的签名过程,反正是没找到,然后百度各种关键词, 此贴刚好没排在搜索前排,然后各种尝试。当返回成功的时候,发现就是这么简单的几句代码,卧槽。希望你没遇到这问题。
setUserStorage这个接口的签名内容是什么hmac_sha256的key我知道是session_key。但是postdata的内容呢? 是kv_list的json还是说 除了signature和sig_method,包含access_token、openid、appid、kv_list的一个object的json格式??
2019-10-24