import AES from 'crypto-js/aes.js';
import utf8 from 'crypto-js/enc-utf8.js';

class AESCrypto {
    /**
     * 密钥
     * @type {string}
     */
    static #AES_KEY = import.meta.env.VITE_AES_KEY;

    /**
     * AES加密
     * @param context {string} 加密内容
     */
    static encrypt = (context) => {
        return AES.encrypt(context, this.#AES_KEY).toString();
    }

    /**
     * AES解密
     * @param context {string}
     * @return {string}
     */
    static decrypt = (context) => {
        const bytes = AES.decrypt(context, this.#AES_KEY);
        return bytes.toString(utf8);
    }
}

export default AESCrypto;
