import CryptoJS from 'crypto-js';

const KEY = 'GZFkEC$u*9xWdQsy';
const IV = 'UKUEWnKv4l2KkZCX';

/**
 * AES CBC模式 PKCS5Padding加密
 */
export function encryptAES(plaintext) {
  const key = CryptoJS.enc.Utf8.parse(KEY);
  const iv = CryptoJS.enc.Utf8.parse(IV);
  const encrypted = CryptoJS.AES.encrypt(plaintext, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

/**
 * AES CBC模式 PKCS5Padding解密
 */
export function decryptAES(ciphertext) {
  const key = CryptoJS.enc.Utf8.parse(KEY);
  const iv = CryptoJS.enc.Utf8.parse(IV);
  const decrypted = CryptoJS.AES.decrypt(ciphertext, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
}
