qq_44705968
壹个丶蓝人
采纳率100%
2020-09-06 10:18

后台接收前台参数出现编码不对的问题

说白了就是前台传的参数里面带了“==”“\”这样的符号,后台拿的时候编译除了问题,怎么解决这个问题(具体代码如下)
前台对密码进行了加密,通过ajax将加密后的密码(YEiS0vPXNRlPwfpPwwvo/Q==)给后台解密。

   var key = CryptoJS.enc.Utf8.parse($key);
            var pass = CryptoJS.enc.Utf8.parse($pass);
            var encrypted = CryptoJS.AES.encrypt(pass, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
            var encryptedPwd = encrypted.toString();

            //用户登录
            $.ajax({
                type: "post",
                url: "<%=request.getContextPath()%>/login/userLogin",
                data: {loginId: $loginId, pass: encryptedPwd ,key: $key},

                dataType: "json",
                                ......

后台接收参数

    @ResponseBody
    @RequestMapping(value = "/userLogin", method = RequestMethod.POST)
    public AjaxJson userLogin() throws Exception {
        Map<String, Object> param = getRequestMapSingle();
        String pass = param.get("pass").toString();
        String key = param.get("key").toString();
        String password = AesUtils.decrypt(pass,key);
        param.put("pass",password);
        AjaxJson ajaxJson = new AjaxJson();
        System.out.println(param);
        try {
            ajaxJson = loginServiceImpl.userLogin(request, response, param);
        } catch (Exception e) {
            logger.error("Exception:", e);
        }

        return ajaxJson;
    }

String pass = param.get("pass").toString(); 拿到的密码是这样的

YEiS0vPXNRlPwfpPwwvo\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B26\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B23x2f\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B3BQ\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B26\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B23x3d\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B3B\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B26\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B23x3d\5c x26quot\5c x3B\5c x26amp\5c x3Bchrw\5c x26\5c x23x28\5c x3B37\5c x26\5c x23x29\5c x3B\5c x26amp\5c x3B\5c x26quot\5c x3B3B

请求大佬帮忙解答,处理,万分感谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • VICTOR_fusheng VICTOR_fusheng 7月前

    可以让页面对加密后的密码进行一次urlencode编码,你拿到后urldecode解码就行

    点赞 1 评论 复制链接分享
  • dabocaiqq dabocaiqq 7月前