import * as CryptoJS from 'crypto-js' import { AES_CONFIG } from './configure' const cbc_key = CryptoJS.enc.Utf8.parse(AES_CONFIG.AES_KEY) const cbc_iv = CryptoJS.enc.Utf8.parse(AES_CONFIG.AES_IV) /** * 加解密开关 * 默认参数需要加密 * @type {boolean} */ const encryptEnabled= false; // /** // * 默认后台会自动加密 // * @type {boolean} // */ // const decryptEnabled=true; /** * 加密 * @param word * @returns {string} */ export const encryptCBC = function(word) { const srcs = CryptoJS.enc.Utf8.parse(word) const encrypted = CryptoJS.AES.encrypt(srcs, cbc_key, { iv: cbc_iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) return encrypted.toString() } /** * 解密 * @param word * @returns {*} */ export const decryptCBC = function(word) { // if(!decryptEnabled){ // return word; // } const encrypted = CryptoJS.AES.decrypt(word, cbc_key, { iv: cbc_iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) return encrypted.toString(CryptoJS.enc.Utf8) }