aes_endecrypt.js 747 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
/**
* 工具类
* sKey可自定义
*/

//加密
export let enCode=(plaintText)=>{
var that = this
// var CryptoJS = require("crypto-js");
var sKey = "abc123456789"
sKey = CryptoJS.enc.Utf8.parse(sKey)
var ciphertext = CryptoJS.AES.encrypt(plaintText, sKey, {
iv: sKey,
mode: CryptoJS.mode.CBC, // CBC算法
padding: CryptoJS.pad.ZeroPadding, //使用pkcs7 进行padding 后端需要注意
}).toString();
return ciphertext;
}

//解密
export let deCode=(ciphertext)=>{
var sKey = "abc123456789"
// var CryptoJS = require("crypto-js");
sKey = CryptoJS.enc.Utf8.parse(sKey)
return CryptoJS.AES.decrypt(ciphertext, sKey, {
iv: sKey,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8);
}