登录加密

如题所述

第1个回答  2022-07-20
使用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; //返回加密结果

  }
相似回答