import crypto from "crypto";
import { AES_KEY } from "./constants";

// EncryptUtil.java 대응 - AES 암호화
export function encrypt(text: string): string {
  const key = Buffer.from(AES_KEY, "utf8");
  const cipher = crypto.createCipheriv("aes-128-ecb", key, null);
  let encrypted = cipher.update(text, "utf8", "base64");
  encrypted += cipher.final("base64");
  return encrypted;
}

export function decrypt(encrypted: string): string {
  const key = Buffer.from(AES_KEY, "utf8");
  const decipher = crypto.createDecipheriv("aes-128-ecb", key, null);
  let decrypted = decipher.update(encrypted, "base64", "utf8");
  decrypted += decipher.final("utf8");
  return decrypted;
}
