// @ts-ignore
import * as CryptoJS from 'crypto-js'

const AES_KEY = 'fxboot!!fxboot!!'
export function encrypt(val: string) {
  const key = CryptoJS.enc.Latin1.parse(AES_KEY)
  const encrypted = CryptoJS.AES.encrypt(val, key, {
    iv: key,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return encrypted.toString()
}

export function decrypt(val: string) {
  const key = CryptoJS.enc.Latin1.parse(AES_KEY)
  const decrypted = CryptoJS.AES.decrypt(val, key, {
    iv: key,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return CryptoJS.enc.Utf8.stringify(decrypted).toString()
}
