crypto-js加密
2021-03-17 13:26
标签:vue enc ring fun ted ecb from rop mode crypto-js加密 标签:vue enc ring fun ted ecb from rop mode 原文地址:https://www.cnblogs.com/feibiubiu/p/12784310.html/**加解密类 */
import Vue from ‘vue‘
//加密
import CryptoJS from ‘crypto-js‘;
// Vue.use(cryptojs);
export function encrypt(word,iv1,keyStr){
keyStr=keyStr?keyStr:‘absoietlj32fai12‘;
var key=CryptoJS.enc.Utf8.parse(keyStr);
const iv=CryptoJS.enc.Utf8.parse(iv1);
var srcs=CryptoJS.enc.Utf8.parse(word);
var encrypted=CryptoJS.AES.encrypt(srcs,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding});
// var encrypted=CryptoJS.AES.encrypt(srcs.ciphertext,key,{mode:CryptoJS.mode.ECB,padding:CryptoJS.pad.Pkcs7});
var encstr=CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
return encstr;
}
//解密 成功解密
export function decrypt(word,iv1,keyStr){
keyStr=keyStr?keyStr:‘absoietlj32fai12‘;
if(!word){
return
}
const iv=CryptoJS.enc.Utf8.parse(iv1);
var key = CryptoJS.enc.Utf8.parse(keyStr);
var decrypt = CryptoJS.AES.decrypt(word,key,{iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding});
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}