vue 项目中登录中密码加密
用户登录密码传输未加密,不太安全
加密方法有js-sha256、aes、des、ras
一、aes.js AES密码加密、解密
安装npm install crypto-js
var CryptoJS = require('crypto-js')
var key = 'abcdefgabcdefg12'
export function encrypt(text) {
var encrypted = CryptoJS.AES.encrypt(text, CryptoJS.enc.Utf8.parse(key), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
});
return encrypted.toString();
}
export function decrypt(text) {
var result = CryptoJS.AES.decrypt(text, CryptoJS.enc.Utf8.parse(key), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
return result.toString(CryptoJS.enc.Utf8)
}
二、具体代码
import { encrypt, decrypt } from '@/assets/js/aes.js'
//登录时候
password:encrypt(this.account.password).toString()
//存储时候
encrypt(this.account.password).toString()
//读取存储值
decrypt(accountInfo.password)
三级目录
链接: https://blog.csdn.net/qq_34707272/article/details/121857485.
链接: https://blog.csdn.net/weixin_55560445/article/details/114419955.