import CryptoJS from "crypto-js";
import padZeropadding from "crypto-js/pad-zeropadding";

let key = "4341100000";
let iv = "4341100000";
export function encrypt(data) {
  let key1 = CryptoJS.enc.Latin1.parse(key);
  let iv1 = CryptoJS.enc.Latin1.parse(iv);
  return CryptoJS.AES.encrypt(data, key1, {
    iv: iv1,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding,
  }).toString();
}

export function decrypt(data) {
  console.log(22222222222, data);
  let ciphertextUtf8 = (data + "").replace(/\n*$/g, "").replace(/\n/g, "");
  console.log(ciphertextUtf8, "ciphertextUtf8");
  let key1 = CryptoJS.enc.Latin1.parse(key);
  let iv1 = CryptoJS.enc.Latin1.parse(iv);
  let decrypted = CryptoJS.AES.decrypt(ciphertextUtf8, key1, {
    iv: iv1,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding,
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
}
