如题:uni-app 怎么安装CryptoJS并实现加密
mycliang
- 发布:2018-12-20 15:37
- 更新:2022-06-30 09:51
- 阅读:4709
2***@qq.com
那具体怎么搞的,说下嘛
2019-04-02 17:23
mycliang (作者)
回复 2***@qq.com:
1.将crypto-js.js复制到common文件夹
2.新建utils.js,内容如下
import Vue from 'vue'
import CryptoJS from './crypto-js.js'
const keys = '密码';
export default {
AES_encrypt(word) {
var key = CryptoJS.enc.Utf8.parse(keys);
var srcs = CryptoJS.enc.Utf8.parse(word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
},
AES_decrypt(word) {
var key = CryptoJS.enc.Utf8.parse(keys);
var decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
}
3.main.js增加如下
import utils from './common/utils.js'
Vue.prototype.$Utils = utils;
4.使用this.$Utils.AES_decrypt('要加密内容');
2019-04-18 21:53