//import CryptoJS from "./cryptoJs";
import CryptoJS from "crypto-js";
//秘钥
const CRYPTOJSKEY = "1qaz@WSX3edc$RFV";
// 加密
export function encrypt(plaintText) {
  var plaintText = plaintText;
  var iv = CryptoJS.enc.Utf8.parse("16-Bytes--String");
  var options = {
    iv: iv,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  };
  var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  var encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
  var encryptedBase64Str = encryptedData.toString();
  encryptedBase64Str = encryptedBase64Str;
  return encryptedBase64Str;
}
//解密
export function decrypt(encryptedBase64Str) {
  var vals = encryptedBase64Str;
  var options = {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  };
  var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
  var decryptedData = CryptoJS.AES.decrypt(vals, key, options);
  var decryptedStr = CryptoJS.enc.Utf8.stringify(decryptedData);
  return decryptedStr;
}
