日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

前端解密后台加密算法优化思想

發(fā)布時間:2025/3/19 HTML 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端解密后台加密算法优化思想 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

場景

記一次加解密算法優(yōu)化過程。

實現(xiàn)

1.開始

后臺查詢出所有數(shù)據(jù),并循環(huán)對所有的字段進(jìn)行加密,

在前段循環(huán)對所有字段進(jìn)行循環(huán)解密。

2.一次優(yōu)化

后臺只對關(guān)鍵字段進(jìn)行加密,前段只對關(guān)鍵字段進(jìn)行解密。

3.二次優(yōu)化

后臺對每條記錄,即每個對象的關(guān)鍵字段進(jìn)行循環(huán)取出,拼接成字符串,

然后再對所有對象進(jìn)行加密。

4.三次優(yōu)化

后臺先循環(huán)取出所有的對象的所有字段,拼接成字符串,字段之間以及

對象之間用分隔符分隔,然后拼接成一個字符串,也就是在循環(huán)外調(diào)用加密算法。

然后前段實現(xiàn)一次解密,然后遍歷賦值。

部分代碼

單個關(guān)鍵字段進(jìn)行加解密

后臺:

data2 = this.service.queryAll(map);String key =rsaService.getPublicKey();String totalWithOutLine="";for(orderComfirm oc:data2){SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");Date date = new java.sql.Date(format1.parse(sdf.format(oc.getDeliverDate())).getTime());oc.setDeliverDate(date);if(oc.getIsOnline()==1) {oc.setTotalWithOutLine(oc.getTotalOnline());oc.setTotalOnline(null);}if(oc.getIsOnline()==0) {oc.setTotalWithOutLine(oc.getTotalNoOnline());oc.setTotalNoOnline(null);}if(oc.getTotalWithOutLine()!=null) {String totalWithOutLineStr=String.valueOf(oc.getTotalWithOutLine());if(!"".equals(totalWithOutLine)) {totalWithOutLine=totalWithOutLine+","+totalWithOutLineStr;}else {totalWithOutLine=totalWithOutLineStr;}}oc.setTotalWithOutLine(null);oc.setPrice(null);oc.setState(oc.getStateEn());oc.setTotal(null);String week = DateConvert.getWeek(oc.getDeliverDate()).getChineseName();week = "周"+week.substring(2);oc.setWeek(week);}String totalWithOutLineEn=rsaService.encrypt(key,totalWithOutLine);data2.get(0).setTotalEn(totalWithOutLineEn);jsonResult.setData(data2);jsonResult.setStatus(true);jsonResult.setMessage("接口訪問成功!");LogService.getInstance(this).debug("獲取列表成功!");?}catch(Exception ex) {jsonResult.setStatus(false);jsonResult.setMessage("接口訪問失敗");LogService.getInstance(this).error("獲取數(shù)據(jù)失敗:" + ex.getMessage(), ex);}return jsonResult;}

前端:

var list = data.data;var totalWithOutLineStr = list[0].totalEn;totalWithOutLineStr = RSADecrypt(totalWithOutLineStr);var totalPriceArr=totalWithOutLineStr.split(",");if(list.length>0){$("#ok_order").css("display","block");??????????? ??}for(var i=0;i<list.length;i++){list[i].totalWithOutLine=totalPriceArr[i];if(list[i].deliverDate){list[i].deliverDate=Covert(list[i].deliverDate);}//list[i].deliverDate = list[i].deliverDate.replace(/-/g,".");if(list[i].total!=null){list[i].total = commafy(list[i].total);}}

多個關(guān)鍵字段進(jìn)行加解密

typeList = this.tbComfirmListService.getCates(map);for(CateList cate : typeList){Map<String,Object> map1 = new HashMap<>();map1.put("time", orderId);map1.put("caName", cate.getCaName());if(code!=null&&!code.equals("")){map1.put("oid", code);}else{map1.put("oid", code1);}if(online!=null&&!online.equals("")){map1.put("online", "0");}List<ComfirmList> cst = tbComfirmListService.queryOrder(map1);cate.setList(cst);}}BigDecimal totalPrice=new BigDecimal("0.00");for(CateList cl:typeList) {totalPrice=totalPrice.add(cl.getPayment());}String cateEncry="";String encryAfter ="";for(CateList cl:typeList) {cl.setTotalPrice(totalPrice);if(!"".equals(cateEncry)) {cateEncry=cateEncry+"="+totalPrice.toString();}else {cateEncry=totalPrice.toString();}cateEncry=cateEncry+"-"+cl.getPayment().toString();cl.setPayment(null);cl.setTotalPrice(null);for(ComfirmList c:cl.getList()) {//對num和totalFee進(jìn)行拼接加密,以"."分割數(shù)量和價格,","分割每一個comfirmList對象if(!"".equals(encryAfter)) {encryAfter=encryAfter+"="+c.getNum().toString();}else {encryAfter=c.getNum().toString();}encryAfter=encryAfter+"-"+c.getPrice().toString();c.setNum(null);c.setPrice(null);}}String result=cateEncry+";"+encryAfter;cateEncry=rsaService.encrypt(key,result);if(typeList.get(0)!=null) {typeList.get(0).setTotalPriceEn(cateEncry);}jsonResult.setData(typeList);jsonResult.setStatus(true);jsonResult.setMessage("接口訪問成功!");LogService.getInstance(this).debug("獲取列表成功!");?

前端:

var list = data.data;for(var i=0;i<list.length;i++){if(list[i].payment!=null){list[i].payment = commafy(list[i].payment);}list[i].totalPrice = commafy(list[i].totalPrice);for(var j=0;j<list[i].list.length;j++){list[i].list[j].price = commafy(list[i].list[j].price);}}

?

總結(jié)

以上是生活随笔為你收集整理的前端解密后台加密算法优化思想的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。