import CryptoJS from 'crypto-js';
/**
 * CryptoJS加密
 */
export function localEncrypt(word, keyStr) {
  keyStr = keyStr ? keyStr : "BTRH201911PERMIS";
  let key = CryptoJS.enc.Utf8.parse(keyStr);
  let srcs = CryptoJS.enc.Utf8.parse(word);
  let encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

/**
 * CryptoJS解密
 */
export function localDecrypt(word, keyStr) {
  keyStr = keyStr ? keyStr : "BTRH201911PERMIS";
  var key = CryptoJS.enc.Utf8.parse(keyStr);
  var decrypt = CryptoJS.AES.decrypt(word, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}

export default {
  localEncrypt,
  localDecrypt
}
