aes-128-cbc(utf8环境,密文使用Hex编码)
import CryptoJS from "crypto-js";
export default {
encrypt(data, keyStr = 'fXoY5SYpr2uz4yFr', ivStr = 'UV4kibe6BDBN3HrE') {
let key = CryptoJS.enc.Utf8.parse(keyStr);
let iv = CryptoJS.enc.Utf8.parse(ivStr);
let encrypted = CryptoJS.AES.encrypt(data, key, {iv: iv});
return encrypted.toString(CryptoJS.format.Hex);
},
decrypt(data, keyStr = 'fXoY5SYpr2uz4yFr', ivStr = 'UV4kibe6BDBN3HrE') {
let key = CryptoJS.enc.Utf8.parse(keyStr);
let iv = CryptoJS.enc.Utf8.parse(ivStr);
let decrypted = CryptoJS.AES.decrypt(data, key, {iv: iv,format: CryptoJS.format.Hex});
return decrypted.toString(CryptoJS.enc.Utf8);
}
}