遇到了同样的问题,不知道怎么解决
填充无效无法被移除[图片] 有时可以,有时不可以,直接报填充无效无法被移除, 加密数据:FJOD8oQ8l/4awbPuNMfdb+oQjMFjYlgDyx8qOkbViMG5CCs8OlSFs66Y2oYgRFg40oA98lansvmsOFQ3h4+dW19mNo0c+dCWpLPf2XT6UzZ16BL+QPIN+29pqmrDbR3BEd2dlaOsiZmeAVQFov2TPfANZyLMBZNk9w9cA8IGoivQ/0vZoy3teFfeHykTdsjtZgLt4uBH9VBsoHzXyZCCQzcprmIabNjgZ2zEeGcrBJD5OhlDSJftTint9tPYNdRZo1GgZpkdf7rupzc9pQ0aOXNL/LdkLWl/GutI6OOpb1Vs3prBn2dnMn7zv/SshlR3wk91RwMhpL7gEy4QmEJVzPQgwBjFGyE68e5NYwxXdHf4cGLeckyChsaeIvSqi1RR1C4CpKcsxNI/ZrUvKmmOEADm6vR4xiXShUT8iYQLyPSNSetOoNEIv4Lqutu9Vh2yhHszW47vS/N0zZJ0hz5bp/m1v2i3qzOfOV/6Lh1YEG8= 密钥:H186u5/0NMFynRLcEv0CKQ== IV:bH0I4SMZEc33MlSoezDwSA== 请问是不是密钥或者IV出错了
2018-09-27我这边获取用户手机号码也是,绝大部分都是填充无效,无法被移除,很少会获取正确的
DecodeUserInfo返回填充无效,无法被移除- 调用jscode2session返回 Session:{"session_key":"MC+n9QzMTP4puANt5+fIJw==","openid":"oROFY5D_dt4hmLUoIRJ9bCrnUwrU","unionid":"oZJY10vD6kXy8xvI6NUEC21FoZ4s"}& 此时获取到的session_key是有问题的,使用这个session_key去Decode返回 “填充无效,无法被移除”
2018-09-27我也是遇到这种情况,不知道怎么解决了
小程序getPhoneNumber 解密手机号时,偶尔会出现填充无效,无法被移除客户端 getPhoneNumber: function (e) { let that=this; wx.login({ success: function (res) { if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { wx.navigateTo({ url: '../../pages/userLogin/userLogin', }); } else { if (e.detail.errMsg == 'getPhoneNumber:fail:cancel to confirm login') { wx.navigateTo({ url: '../../pages/userLogin/userLogin?url='+that.data.url }); } else { //console.log(res.code); wx.request({ url: api.AESdecrypt, data: { 'encryptedDataStr': e.detail.encryptedData, 'code': res.code, 'iv': e.detail.iv }, method: 'post', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (data) { console.log(data); app.globalData.userInfo = data.data.data; setTimeout(function(){ wx.navigateBack({ changed: true });//返回上一页 },500); }, error: function () { tip.showToast('error'); }, fail: function (err) { tip.showToast(err); } }) } } } }); }, 服务端 try { string encryptedDataStr = System.Web.HttpContext.Current.Request["encryptedDataStr"], code = System.Web.HttpContext.Current.Request["code"], iv = System.Web.HttpContext.Current.Request["iv"]; ReturnData resultMsg = new ReturnData(); resultMsg.state = (int)StatusCodeEnum.Success; resultMsg.message = StatusCodeEnum.Success.GetEnumText(); string strresult = ""; string Appid = "Appid"; string Secret = "Secret "; string grant_type = "authorization_code"; GetUsersHelper GetUsersHelper = new Controllers.GetUsersHelper(); //向微信服务端 使用登录凭证 code 获取 session_key 和 openid string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Appid + "&secret=" + Secret + "&js_code=" + code + "&grant_type=" + grant_type; Stream s_re = WebRequest.Create(url).GetResponse().GetResponseStream(); StreamReader sr = new StreamReader(s_re, Encoding.UTF8); string strLine = sr.ReadToEnd(); sr.Close(); //将字符串转换为json格式 JObject jo = (JObject)JsonConvert.DeserializeObject(strLine); result res = new result(); try { //微信服务器验证成功 res.openid = jo["openid"].ToString(); res.session_key = jo["session_key"].ToString(); } catch (Exception) { //微信服务器验证失败 res.errcode = jo["errcode"].ToString(); res.errmsg = jo["errmsg"].ToString(); WriteInfo(res.errmsg); } if (!string.IsNullOrEmpty(res.openid)) { //用户数据解密 strresult = GetUsersHelper.AESDecrypt(encryptedDataStr, res.session_key,iv);//.AES_decrypt(encryptedDataStr,res.session_key,iv);// JObject jos = (JObject)JsonConvert.DeserializeObject(strresult); ResultInfo ress = new ResultInfo(); ress.phoneNumber = jos["phoneNumber"].ToString(); var model = Ioc.Get<IUserRepository>().FindMobile(ress.phoneNumber); resultMsg.data = model; } else { strresult = null; resultMsg.data = strresult; } return resultMsg; } catch (Exception ex) { WriteInfo(ex.Message); return new ReturnData { state=200, message="error", data=null }; } 解密.net public string AESDecrypt(string inputdata, string AesKey, string AesIV) { try { RijndaelManaged rijalg = new RijndaelManaged(); //----------------- //设置 cipher 格式 AES-128-CBC rijalg.KeySize = 128; rijalg.Padding = PaddingMode.PKCS7; rijalg.Mode = CipherMode.CBC; rijalg.Key = Convert.FromBase64String(AesKey); rijalg.IV = Convert.FromBase64String(AesIV); byte[] encryptedData = Convert.FromBase64String(inputdata); //解密 ICryptoTransform decryptor = rijalg.CreateDecryptor(rijalg.Key, rijalg.IV); string result; using (MemoryStream msDecrypt = new MemoryStream(encryptedData)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { result = srDecrypt.ReadToEnd(); } } } return result; } catch (Exception ex) { ApiUserController apis = new ApiUserController(); apis.WriteInfo("jiemi"+ex.Message); return null; } }
2018-09-27