import CryptoJS from "crypto-js";

// const key = 'ew0ov3n1xurvhlhl'
// const iv = 'gbb9qknndntteqc1'
// const utf8Parse = (str) => CryptoJS.enc.Utf8.parse(str);
// export function cryptoDecode (encodedStr){
//     debugger
//     const decryptedBytes = CryptoJS.AES.decrypt(encodedStr, utf8Parse(key), {
//         mode: CryptoJS.mode.CBC,
//         padding: CryptoJS.pad.Pkcs7,
//         iv: utf8Parse(iv)
//     });

//     const decryptedText = decryptedBytes.toString(CryptoJS.enc.Utf8);
//     return decryptedText;
// };

const data = {
  key: "ew0ov3n1xurvhlhl",
  iv: "gbb9qknndntteqc1"
};

export function utf8Parse(str) {
  return CryptoJS.enc.Utf8.parse(str);
}
export function base64(str) {
  return CryptoJS.enc.Base64.stringify(utf8Parse(str)).toString();
}

export function aesEncode(str, key, iv) {
  const result = CryptoJS.AES.encrypt(utf8Parse(str), utf8Parse(key), {
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
    iv: utf8Parse(iv)
  }).toString();

  return result;
}
export function cryptoDecode(str) {
  return base64(aesEncode(str, data.key, data.iv));
}
