import AesEncryptJS from 'crypto-js' export default { /** * AES加密 * * @param word * @param encryKey */ AESEncrypt(word: string, encryKey: string): string { const key = AesEncryptJS.enc.Utf8.parse(encryKey) const srcs = AesEncryptJS.enc.Utf8.parse(word) const encrypted = AesEncryptJS.AES.encrypt(srcs, key, { mode: AesEncryptJS.mode.ECB, padding: AesEncryptJS.pad.Pkcs7, }) return encrypted.toString() }, /** * AES解密 * * @param word * @param encryKey */ AESDecrypt(word: string, encryKey: string): any { const key = AesEncryptJS.enc.Utf8.parse(encryKey) const decrypt = AesEncryptJS.AES.decrypt(word, key, { mode: AesEncryptJS.mode.ECB, padding: AesEncryptJS.pad.Pkcs7, }) const ret = AesEncryptJS.enc.Utf8.stringify(decrypt).toString() try { return JSON.parse(ret) } catch { return ret } }, }