import CryptoJS from 'crypto-js'

const hostList = ['ltmarketui.yijiesudai.com']
const keyVal = !hostList.includes(window.location.host) ? 'qhTkg7cRo8Q7X2Zg' : '3eIn1OL2X7H3yW1b'
const ivVal = !hostList.includes(window.location.host) ? 'yFjzJdKLMgmJxUkX' : 'Jvb3PyimIaDRpNi8'

const key = CryptoJS.enc.Utf8.parse(keyVal)
const iv = CryptoJS.enc.Utf8.parse(ivVal)

// 加密
export const Encrypt = (pass: any) => {
  const password = CryptoJS.enc.Utf8.parse(pass)
  return CryptoJS.AES.encrypt(password, key, {
    mode: CryptoJS.mode.CBC,
    iv: iv,
    padding: CryptoJS.pad.Pkcs7
  }).toString()
}

// 解密
export const Decrypt = (pass: any) => {
  return CryptoJS.AES.decrypt(pass, key, {
    mode: CryptoJS.mode.CBC,
    iv: iv,
    padding: CryptoJS.pad.Pkcs7
  }).toString(CryptoJS.enc.Utf8)
}
