import CryptoJS from 'crypto-js'
export const crypto = {
options() {
return {
key: CryptoJS.enc.Utf8.parse('asdfghjklqwe'),
iv: CryptoJS.enc.Utf8.parse('123')
}
},
//加密
getAES(data) {
const { key, iv } = this.options()
const encrypted = CryptoJS.AES.encrypt(data, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
},
//解密
getDAes(encrypted) {
const { key, iv } = this.options()
const decrypted = CryptoJS.AES.decrypt(encrypted, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
})
return decrypted.toString(CryptoJS.enc.Utf8)
}
}