敏感字段使用国密sm2.js加密处理

1、在前端页面加上如下sm2.js

2、在ajax中将需要加密的字段加密

//加密处理
goodsPrice1 = sm2Encrypt(goodsPrice1, publicKey);
shippingFee1 = sm2Encrypt(shippingFee1, publicKey);
goodsAmount1 = sm2Encrypt(goodsAmount1, publicKey);
$.ajax({
    url: '${base}/444/save',
    type: 'post',
    data: {
        goodsPrice1: goodsPrice1,
        shippingFee1: shippingFee1,
        goodsAmount1: goodsAmount1
    },

3、后台Controller中传入相关参数,并进行解密

 @RequestMapping("/save")
    public
    @ResponseBody
    Map save(
           HttpServletRequest request,
            @RequestParam(value = "goodsPrice1") String goodsPrice,
            @RequestParam(value = "shippingFee1") String shippingFee,
            @RequestParam(value = "goodsAmount1") String goodsAmount,
            @RequestParam(value = "inquiryId") String inquiryId,
            @RequestParam(value = "contactName") String contactName,
            @RequestParam(value = "mobPhone") String mobPhone,
            @RequestParam(value = "contactEmail") String contactEmail,
            @RequestParam(value = "orgName") String orgName,
            @ModelAttribute Quotation quotation) {

 //解密
            if(StringUtils.isNotBlank(goodsPrice)){
                BigDecimal goodsPrice1 =new BigDecimal(XssFilterUtil.filterString(Sm2Utils.decrypt(goodsPrice)));
                quotation.setGoodsPrice(goodsPrice1);
            }
            if(StringUtils.isNotBlank(shippingFee)){
                BigDecimal shippingFee1 =new BigDecimal(XssFilterUtil.filterString(Sm2Utils.decrypt(shippingFee)));
                quotation.setShippingFee(shippingFee1);
            }
            if(StringUtils.isNotBlank(goodsAmount)){
                BigDecimal goodsAmount1 =new BigDecimal(XssFilterUtil.filterString(Sm2Utils.decrypt(goodsAmount)));
                quotation.setGoodsAmount(goodsAmount1);
            }

 

 

 

你可能感兴趣的:(Spring)