代码:
public static Map<String, String> decryptMapFromResponseString(String aesKey, String responseString) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bt = aesKey.getBytes();
md.update(bt);
String strDes = bytes2Hex(md.digest());
SecretKeySpec key = new SecretKeySpec(strDes.getBytes(), "AES");
Security.addProvider(new BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] base64ByteArr = Base64.decode(responseString);
String result = new String(cipher.doFinal(base64ByteArr), "utf-8");
Map<String, String> map = WXPayUtil.xmlToMap(result);
return map;
}
报错:
Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026) at javax.crypto.Cipher.init(Cipher.java:1245) at javax.crypto.Cipher.init(Cipher.java:1186) at com.hct.lottery.payment.main.pay.weixin.WeixinUtil.decryptMapFromResponseString(WeixinUtil.java:265) at com.hct.lottery.payment.main.pay.weixin.WeixinUtil.main(WeixinUtil.java:338)
什么情况呢?查了半天也没查出来问题,唉!
替换local_policy.jar和US_export_policy.jar 即可
https://blog.csdn.net/qq_44776721/article/details/113701498
java demo 亲测可用