美文网首页
登录加密

登录加密

作者: _鸭鸭 | 来源:发表于2021-02-22 18:36 被阅读0次

    使用sha256加密方式

    原理:前端获取随机值,进行多次加密后下发给后端比对后端同样方式加密出来的密码的结果是否一致。

    Sha256加密的出来的数据是不可逆的没有解密。

    import CryptoJS from "crypto-js";//使用crypto-js的modules

    //对密码进行加密

     let encryptedPwd = encodePwd(password, {

                challenge: Challenge,//先获取的随机值

                userName:username,

                salt: '',

                iIterate: 20  //加密20次

              }, false);

     //密码加密

      encodePwd(szPwd, encodeParam, bIrreversible) {

        let encodeKey = '';

          //secretKey is challenge

          encodeKey = this.sha256(szPwd) + challenge;

          for (let i = 1; i < encodeParam.iIterate; i++) {

           encodeKey = this.sha256(encodeKey);

        return encodeKey; //返回加密结果

      }

    相关文章

      网友评论

          本文标题:登录加密

          本文链接:https://www.haomeiwen.com/subject/vgukfltx.html