前端AES加密
作者:互联网
1、创建crypto.js文件
import CryptoJS from 'crypto-js';
const AESKEY = 'abcdfghigklmnopq';
// 16位密钥,和后端保持一致
const encrypt = (text) => {
let key = CryptoJS.enc.Utf8.parse(AESKEY);
let encrypted = CryptoJS.AES.encrypt(text, key, {
drop: 128,
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
};
// AES加密
export default encrypt;
2、在需要的文件夹上引入
// AES加密
import encrypt from '@/util/crypto'
// Post传参,登录请求
let params = new FormData()
params.append('userName', this.username)
params.append('passWord', encrypt(this.password))
this.axios.post(api.loginUrl, params).then(response =>{
let res = response.data
if (res.success) {
localStorage.setItem('login', true)
localStorage.setItem('wsp_Auth', res.data.token)
localStorage.setItem('wsp_user', JSON.stringify(res.data.user))
this.$router.push({
path: '/index'
})
} else {
this.$message.error(res.message || '系统问题,请联系管理员!')
}
}).catch(err => {
console.error(err)
}).finally(() => {
this.loading.close()
})
完事,证实一下我们的账号密码都是admin
标签:AES,encrypt,res,前端,let,params,加密,CryptoJS 来源: https://blog.csdn.net/Wehter/article/details/120434012