• 后台js解密讲解


    后台加密->解密

    admin 加密为 Ht4EVPcyMtCpsdx1xIGCVg==

    CTRL+U 查看源代码得到加密逻辑

        <script type="text/javascript">
    
            function check() {
                //这里将用户名,密码加密
                var code = 'quying@pingpang';
                var yname = $("#yname").val();
                if (yname == '') {
                    alert("用户名不能为空");
                    return false;
                } else {
                    var newName = secret(yname, code, false);
                    $("#xname").val(newName);
                }
    
    
                var ypassword = $("#ypassword").val();
                if (ypassword == '') {
                    alert("密码不能为空");
                    return false;
                } else {
                    var newPassword = secret(ypassword, code, false);
                    $("#xpassword").val(newPassword);
                }
    
    
            }
    
            //前端加密
            function secret(string, code, operation) {
                code = CryptoJS.MD5(code).toString();
                var iv = CryptoJS.enc.Utf8.parse(code.substring(0, 16));
                var key = CryptoJS.enc.Utf8.parse(code.substring(16));
                if (operation) { //解密
                    return CryptoJS.AES.decrypt(string, key, {
                        iv: iv,
                        padding: CryptoJS.pad.Pkcs7
                    }).toString(CryptoJS.enc.Utf8);
                }
                //加密
                return CryptoJS.AES.encrypt(string, key, {
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString();
            }
    
        </script>
    
    
            if (yname == '') {
                alert("用户名不能为空");
                return false;
            } else {
                var newName = secret(yname, code, false);
                $("#xname").val(newName);
            }
    

    登录时如果账号不为空,创建变量接受加密后的内容。

    跳到secret函数

      //前端加密
            function secret(string, code, operation) {
                code = CryptoJS.MD5(code).toString();
                var iv = CryptoJS.enc.Utf8.parse(code.substring(0, 16));
                var key = CryptoJS.enc.Utf8.parse(code.substring(16));
                if (operation) { //解密
                    return CryptoJS.AES.decrypt(string, key, {
                        iv: iv,
                        padding: CryptoJS.pad.Pkcs7
                    }).toString(CryptoJS.enc.Utf8);
                }
                //加密
                return CryptoJS.AES.encrypt(string, key, {
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString();
            }
    

    code经过MD5加密后重新赋值

    iv(偏移量)为utf-8(Unicode)编码的code前十六位

    key为code除去iv剩下的十六位

    加密模式mode为CBC

    填充padding为Pkcs7

    打开AES在线加密网站尝试 http://tool.chacuo.net/cryptaes/

  • 相关阅读:
    【LeetCode】048. Rotate Image
    【LeetCode】036. Valid Sudoku
    【LeetCode】060. Permutation Sequence
    【LeetCode】001. Two Sum
    【LeetCode】128. Longest Consecutive Sequence
    【LeetCode】081. Search in Rotated Sorted Array II
    【LeetCode】033. Search in Rotated Sorted Array
    顺时针打印矩阵
    矩形覆盖
    二维数组中的查找
  • 原文地址:https://www.cnblogs.com/Gouwa/p/15847405.html
Copyright © 2020-2023  润新知