// import * as w from './node_modules/_crypto-js@4.1.1@crypto-js/crypto-js.js' var CryptoJS = require("./node_modules/_crypto-js@4.1.1@crypto-js/crypto-js.js"); // import aa from 'common.js' export default { // 加密(ECB模式) encrypt(word, keyStr) { // word, keyStr第一个参数是加密的字段名字 第二个是key值(16位) keyStr = keyStr || 'abcdefG1234567' // 密文(密钥) let key = CryptoJS.enc.Utf8.parse(keyStr) let src = CryptoJS.enc.Utf8.parse(word) var encrypted = CryptoJS.AES.encrypt(src, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}) //return encrypted.toString() return CryptoJS.enc.Base64.stringify(encrypted) }, // 解密(ECB模式) decrypt(word, keyStr) { keyStr = keyStr || 'abcdefG1234567' let base64 = CryptoJS.enc.Base64.parse(word); let src = CryptoJS.enc.Base64.stringify(base64); let key = CryptoJS.enc.Utf8.parse(keyStr) let decrypt = CryptoJS.AES.decrypt(src, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7}) return CryptoJS.enc.Utf8.stringify(decrypt).toString() } }