Skip to content

Commit 266aca2

Browse files
committed
#692 修复退款通知解密信息时报Invalid AES key length: 31 bytes异常的问题
1 parent ad8de25 commit 266aca2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import me.chanjar.weixin.common.util.ToStringUtils;
1212
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
1313
import org.apache.commons.codec.binary.Base64;
14+
import org.apache.commons.codec.digest.DigestUtils;
1415

1516
import javax.crypto.Cipher;
1617
import javax.crypto.spec.SecretKeySpec;
@@ -44,12 +45,10 @@ public static WxPayRefundNotifyResult fromXML(String xmlString, String mchKey) t
4445
WxPayRefundNotifyResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundNotifyResult.class);
4546
String reqInfoString = result.getReqInfoString();
4647
try {
47-
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
48-
49-
final MessageDigest md5 = MessageDigest.getInstance("MD5");
50-
md5.update(mchKey.getBytes());
51-
final String keyMd5String = new BigInteger(1, md5.digest()).toString(16).toLowerCase();
48+
final String keyMd5String = DigestUtils.md5Hex(mchKey).toLowerCase();
5249
SecretKeySpec key = new SecretKeySpec(keyMd5String.getBytes(), "AES");
50+
51+
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
5352
cipher.init(Cipher.DECRYPT_MODE, key);
5453
result.setReqInfo(ReqInfo.fromXML(new String(cipher.doFinal(Base64.decodeBase64(reqInfoString)))));
5554
} catch (Exception e) {

0 commit comments

Comments
 (0)