Skip to content

Commit

Permalink
#692 修复退款通知解密信息时报Invalid AES key length: 31 bytes异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Aug 4, 2018
1 parent ad8de25 commit 266aca2
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -11,6 +11,7 @@
import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
Expand Down Expand Up @@ -44,12 +45,10 @@ public static WxPayRefundNotifyResult fromXML(String xmlString, String mchKey) t
WxPayRefundNotifyResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundNotifyResult.class);
String reqInfoString = result.getReqInfoString();
try {
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");

final MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(mchKey.getBytes());
final String keyMd5String = new BigInteger(1, md5.digest()).toString(16).toLowerCase();
final String keyMd5String = DigestUtils.md5Hex(mchKey).toLowerCase();
SecretKeySpec key = new SecretKeySpec(keyMd5String.getBytes(), "AES");

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
result.setReqInfo(ReqInfo.fromXML(new String(cipher.doFinal(Base64.decodeBase64(reqInfoString)))));
} catch (Exception e) {
Expand Down

0 comments on commit 266aca2

Please sign in to comment.