Skip to content

sdk0.2.16 NotificationParser解密时报错Empty key #350

Open
@alv002

Description

错误描述

Caused by: java.lang.IllegalArgumentException: Empty key
at javax.crypto.spec.SecretKeySpec. (SecretKeySpec.java:99)
at com.wechat.pay.java.core.cipher.AbstractAeadCipher.decrypt (AbstractAeadCipher.java:71)
at com.wechat.pay.java.core.notification.NotificationParser.decryptData (NotificationParser.java:154)
at com.wechat.pay.java.core.notification.NotificationParser.getDecryptObject (NotificationParser.java:110)
at com.wechat.pay.java.core.notification.NotificationParser.parse (NotificationParser.java:50)
at com.fish.pay.common.wechat.WeChatPayment.paySuccessCheck (WeChatPayment.java:178)
at com.fish.api.server.controller.api.ApiPayController.renotify (ApiPayController.java:130)
at com.fish.api.server.controller.api.ApiPayController$$FastClassBySpringCGLIB$$e2e58982.invoke ()

重现bug的步骤

java版本1.8.400+,环境为花生壳内网穿透。 body内容
{"id":"a26a97b4-d3a9-53cb-8835-7c0508e14fd5","create_time":"2025-02-22T19:17:11+08:00","resource_type":"encrypt-resource","event_type":"TRANSACTION.SUCCESS","summary":"支付成功","resource":{"original_type":"transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"4u0KHxGb4sA1LnGOQxNIleXuGsL/bcuDWMONMox18M0tyol6oe5tXOJBYHqj7BU2H7YKzz7dhv87pcCeCPZi1wZ2VO83k93Va0vkVZRQ2nIEQshYBXnJ97cUJSqra0+UDSxoYIHn41Rqy8C+U3K9gVhAeSJlOkfXFRhj2SzPCJCcY6780VLuhVldCFjM/dPXqgfXp1YUWMw9dx/jw+mlbr4bPBWEdwBDjhjkkWdgYeh/okHDoX3J7GlOJfuYjSdvXrN/xskKtb/uVeDwY1tpTUGJr2WP+DWk3JlUtdHcyfJ8l+mizeeDnDzulDMY4LrjQqP5bQTkJ/BubLsQyUmTBEO/td61THSxu43ATD4zvSg2vWaq7hEM30MW9lCQCNvrV1VNvpM+hMjD3xAkntkByxqExgC7xLssRLLjnjXtOszmSw23jEwthiC36zSMdoxqW0F5by+LOWnfr8lTQx/XBdRPNxUqn0Db2dRwdBQqbmg9CcUDTUH7WB+RMw+tH3xljwRzap1cbq2BGP4y7L2n1QPDesrmRh5fsQMmR+xn58Yq618iKe1AThxxWuL4j8hX6fs=","associated_data":"transaction","nonce":"kk7cv1zVbia8"}}

预期行为

正常解密信息

导致错误的代码片段

操作系统

windows11

Java 版本

java1.8

wechatpay-java 版本

0.2.16

其他信息

private String getRequestBody(HttpServletRequest request) {
String body;
try (ServletInputStream inputStream = request.getInputStream()
) {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int length; (length = inputStream.read(buffer)) != -1; ) {
result.write(buffer, 0, length);
}
body = result.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
return body;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions