2048
登录
没  有  难  学  的  前  端
登 录
×
<返回上一级

前端密码加密后端解密

javajavascript作者:猿2048志愿者
//加密密码    
$("#Submit").on("click",function(){
    var passWord=$("#passWord").val();
    var eles = [];
      eles.push(passWord);
      var esz = encode("0x12",eles);    
      $("#passWord").val(esz);
})

function encode(key, eles) {
        var keyVal = parseInt(key)
        var arr = []
        for(var i = 0; i < eles.length; ++i) {
            var ele = eles[i]
            arr.push(ele.length ^ keyVal)
            for(var j = 0; j < ele.length; ++j) {
                arr.push(ele[j].charCodeAt(0) ^ keyVal)
            }
        }
        arr.push(keyVal)
        var context = "CV16" + arr.join("%")
        return context;
    }
Map<Integer, String> eszMap = new HashMap<Integer , String>();//解密    
        String passWord = request.getParameter("passWord");
        if(passWord!=null && (!"".equals(passWord))){
            eszMap = apply(passWord);            
            passWord=eszMap.get(0);
        }
        public static Map<Integer, String> apply(String code) {
            try {
                Map<Integer, String> context = new HashMap<Integer, String>();
                List<String> partList = new ArrayList<String>(Arrays.asList(code.substring(4).split("%")));
                for(int index = 0, key = Integer.parseInt(partList.remove(partList.size() - 1)); read(index, key, partList, context); ++index);
                return context;            
            } catch(Exception e) {
                e.printStackTrace();
                return Collections.emptyMap();
            }
        }
        private static boolean read(int index, int key, List<String> partList, Map<Integer, String> context) {
            if(partList.size() <= 0) return false; 
            StringBuilder sb = new StringBuilder();
            for(int i = 0, length = nextElement(key, partList); i < length; ++i) {
                sb.append(Character.toChars(nextElement(key, partList)));
            }
            context.put(index, sb.toString());
            return true;
        }
        private static int nextElement(int key, List<String> partList) {
            return Integer.parseInt(partList.remove(0)) ^ key;
        }

 

本文来源于网络:查看 >
« 上一篇:layui 时间前后节点验证
» 下一篇:css样式
评论
点击刷新
评论
相关博文
×添加代码片段