const crypto = require('crypto'); require('dotenv').config(); const ALGORITHM = 'aes-256-cbc'; const KEY = crypto.createHash('sha256').update(process.env.CRYPT_KEY).digest(); const IV = Buffer.alloc(16, 0); // Python의 chr(0) * 16 과 동일 class AESCipher { static encrypt(text) { const cipher = crypto.createCipheriv(ALGORITHM, KEY, IV); let encrypted = cipher.update(text, 'utf8', 'base64'); encrypted += cipher.final('base64'); return encrypted; } static decrypt(encryptedText) { try { const decipher = crypto.createDecipheriv(ALGORITHM, KEY, IV); let decrypted = decipher.update(encryptedText, 'base64', 'utf8'); decrypted += decipher.final('utf8'); return decrypted; } catch (error) { console.error("복호화 실패:", error.message); return null; // 또는 오류 처리 } } } module.exports = AESCipher;