/*
 * @Author: guicheng 1625811865@qq.com
 * @Date: 2023-02-21 15:36:29
 * @LastEditors: guicheng 1625811865@qq.com
 * @LastEditTime: 2024-04-11 11:35:19
 * @FilePath: /admin/src/utils/encryptByDES.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import CryptoJS from "crypto-js";
const encryptByDES = message => {
  const keyHex = CryptoJS.enc.Utf8.parse("CBTU1dD4Kd5pyiGWTsI10jRQ3SvKusSV");
  const ivHex = CryptoJS.enc.Utf8.parse("DYgjCEIMVrj2W9xN");
  const encrypted = CryptoJS.AES.encrypt(message, keyHex, {
    iv: ivHex,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  const str = CryptoJS.enc.Utf8.parse(encrypted.toString());
  return CryptoJS.enc.Base64.stringify(str);
};
const decryptByDES = message => {
  const encryptedHexStr = CryptoJS.enc.Base64.parse(message);
  const str = encryptedHexStr.toString(CryptoJS.enc.Utf8);
  const keyHex = CryptoJS.enc.Utf8.parse("CBTU1dD4Kd5pyiGWTsI10jRQ3SvKusSV");
  const ivHex = CryptoJS.enc.Utf8.parse("DYgjCEIMVrj2W9xN");
  const decrypt = CryptoJS.AES.decrypt(str, keyHex, {
    iv: ivHex,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
};
export { decryptByDES };
export default encryptByDES;
