import CryptoJS from 'crypto-js' export default class Crypoto { key = CryptoJS.enc.Utf8.parse('zhgd@bonus@zhgd@bonus@1234567890') // 这里找后端要; iv = CryptoJS.enc.Utf8.parse('1234567812345678') /* 加密 */ encrypt(word) { let aqEnnable = true if (!aqEnnable) { return word } var srcs = CryptoJS.enc.Utf8.parse(word) var encrypted = CryptoJS.AES.encrypt(srcs, this.key, { iv: this.iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) return encrypted.toString() } encrypts(word) { const srcs = CryptoJS.enc.Utf8.parse(word) const encrypted = CryptoJS.AES.encrypt(srcs, this.key, { iv: this.iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) const ciphertext = encrypted.ciphertext.toString(CryptoJS.enc.Base64url) // 将加密结果转换为 Base64URL 格式 确认后端要的是Base64URL 还是Base64 这两种编码格式不一样 return ciphertext } decrypt } const jie_mi=true; /** * 解密 * @param word * @returns {*} */ export const decryptCBC = function(word) { if(!jie_mi){ return word; } const encrypted = CryptoJS.AES.decrypt(word, CryptoJS.enc.Utf8.parse('zhgd@bonus@zhgd@bonus@1234567890'), { iv: CryptoJS.enc.Utf8.parse('1234567812345678'), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) return encrypted.toString(CryptoJS.enc.Utf8) }