프런트엔드 암호 암호화 백엔드 복호화

5442 단어
//     
$("#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 eszMap = new HashMap();//     
        String passWord = request.getParameter("passWord");
        if(passWord!=null && (!"".equals(passWord))){
            eszMap = apply(passWord);            
            passWord=eszMap.get(0);
        }
        public static Map apply(String code) {
            try {
                Map context = new HashMap();
                List partList = new ArrayList(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 partList, Map 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 partList) {
            return Integer.parseInt(partList.remove(0)) ^ key;
        }

 
다음으로 전송:https://www.cnblogs.com/bowei/p/9442503.html

좋은 웹페이지 즐겨찾기