import CryptoJS from './libs/crypto-js.min.js'

const aseKey = 'HEHEMINI' //秘钥必须为：8/16/32位
//加密
const encrypt = data => {
    return CryptoJS.AES.encrypt(JSON.stringify(data), CryptoJS.enc.Utf8.parse(aseKey), {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    }).toString()
}
//解密
const decrypt = encrypt => {
    return CryptoJS.AES.decrypt(encrypt, CryptoJS.enc.Utf8.parse(aseKey), {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8)
}

const install = Vue => {
    Vue.prototype.$crypto = {
        encrypt,
        decrypt
    }
}

export default install
