🎨 #3756 【企业微信】修复企业微信 API 回调验签过程中 WxCryptUtil.decrypt 方法可能抛出异常的问题
This commit is contained in:
committed by
GitHub
parent
b94106fd57
commit
28fac4ec2e
@@ -333,14 +333,28 @@ public class WxCryptUtil {
|
|||||||
byte[] bytes = PKCS7Encoder.decode(original);
|
byte[] bytes = PKCS7Encoder.decode(original);
|
||||||
|
|
||||||
// 分离16位随机字符串,网络字节序和AppId
|
// 分离16位随机字符串,网络字节序和AppId
|
||||||
|
if (bytes == null || bytes.length < 20) {
|
||||||
|
throw new WxRuntimeException("解密后数据长度异常,可能为错误的密文或EncodingAESKey");
|
||||||
|
}
|
||||||
byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
|
byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
|
||||||
|
|
||||||
int xmlLength = bytesNetworkOrder2Number(networkOrder);
|
int xmlLength = bytesNetworkOrder2Number(networkOrder);
|
||||||
|
|
||||||
xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET);
|
// 长度边界校验,避免非法长度导致的越界/参数异常
|
||||||
fromAppid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), CHARSET);
|
int startIndex = 20;
|
||||||
|
int endIndex = startIndex + xmlLength;
|
||||||
|
if (xmlLength < 0 || endIndex > bytes.length) {
|
||||||
|
throw new WxRuntimeException("解密后数据格式非法:消息长度不正确,可能为错误的密文或EncodingAESKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlContent = new String(Arrays.copyOfRange(bytes, startIndex, endIndex), CHARSET);
|
||||||
|
fromAppid = new String(Arrays.copyOfRange(bytes, endIndex, bytes.length), CHARSET);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new WxRuntimeException(e);
|
if (e instanceof WxRuntimeException) {
|
||||||
|
throw (WxRuntimeException) e;
|
||||||
|
} else {
|
||||||
|
throw new WxRuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// appid不相同的情况 暂时忽略这段判断
|
// appid不相同的情况 暂时忽略这段判断
|
||||||
|
|||||||
Reference in New Issue
Block a user