forked from chanjarster/weixin-java-tools
-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
加解密的异常处理办法
Binary Wang edited this page Jul 13, 2021
·
6 revisions
如果在加解密的过程中出现java.security.InvalidKeyException: Illegal key size
,则需要下载一个东西:
- JRE/JDK 6:http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
- JRE/JDK 7:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
- JRE/JDK 8u151 之前版本:http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
- JRE/JDK 8u151 之后版本已经内置无限制权限策略文件,只需将
$JAVA_HOME/jre/lib/security/java.security
文件中的#crypto.policy=unlimited
解除注释即可
如果安装了JRE,将两个jar文件放到$JAVA_HOME/lib/security
目录下覆盖原来的文件
如果安装了JDK,将两个jar文件放到$JAVA_HOME/jre/lib/security
目录下覆盖原来文件
如果是使用了工具可能内置了JRE,需要在工具引用的目录下面将两个jar文件放到/jre/lib/security
目录下覆盖原来的文件
String encType = request.getParameter("encrypt_type");
String nonce = request.getParameter("nonce");
String timestamp = request.getParameter("timestamp");
String msgSignature = request.getParameter("msg_signature");
String signature = request.getParameter("signature");
String openid = request.getParameter("openid");
log.info("接收微信请求:[openid=[{}], [openid=[{}],[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[{}] ",
appid, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
// 请求里面没有对应信息。 // if (!this.wxMpService.switchover(appid)) { //appid // throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid)); // }
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}
return ResponseEntity.ok("");