"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var encryption_exports = {}; __export(encryption_exports, { decrypt: () => decrypt, encrypt: () => encrypt }); module.exports = __toCommonJS(encryption_exports); var import_crypto = require("crypto"); var import_env = require("./env"); const ALGORITHM = "aes-256-gcm"; const KEY = Buffer.from(import_env.env.ENCRYPTION_KEY, "hex"); function encrypt(plaintext) { const iv = (0, import_crypto.randomBytes)(12); const cipher = (0, import_crypto.createCipheriv)(ALGORITHM, KEY, iv); const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]); const authTag = cipher.getAuthTag(); return Buffer.concat([iv, authTag, encrypted]).toString("base64"); } function decrypt(ciphertext) { const buf = Buffer.from(ciphertext, "base64"); const iv = buf.slice(0, 12); const authTag = buf.slice(12, 28); const encrypted = buf.slice(28); const decipher = (0, import_crypto.createDecipheriv)(ALGORITHM, KEY, iv); decipher.setAuthTag(authTag); return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8"); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { decrypt, encrypt }); //# sourceMappingURL=encryption.js.map