修改微信授权逻辑

This commit is contained in:
sh
2025-10-20 19:49:28 +08:00
parent 418c22d78d
commit e56a8a285d
8 changed files with 66 additions and 32 deletions

View File

@@ -266,6 +266,15 @@ public class WechatUtil {
byte[] sessionKeyBytes = Base64.getDecoder().decode(sessionKey);
byte[] ivBytes = Base64.getDecoder().decode(iv);
// 2. 验证session_key长度AES-128要求密钥长度为16字节
if (sessionKeyBytes.length != 16) {
throw new RuntimeException("session_key长度错误应为16字节");
}
// 验证iv长度CBC模式下iv长度必须与块大小一致AES为16字节
if (ivBytes.length != 16) {
throw new RuntimeException("iv长度错误应为16字节");
}
// 2. 初始化 AES-128-CBC 解密器使用PKCS5Padding替换PKCS7Padding两者在AES中效果一致
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(sessionKeyBytes, "AES");