diff --git a/src/lib/security.ts b/src/lib/security.ts index 5f8a2dd..ad53966 100644 --- a/src/lib/security.ts +++ b/src/lib/security.ts @@ -2,6 +2,31 @@ import CryptoJS from "crypto-js"; const KEY = CryptoJS.enc.Utf8.parse("kr!-Kfp@-fr0nT-CrypT0-Key-STR!!!"); const IV = CryptoJS.enc.Utf8.parse("kr!-Kfp@Dash-IV!"); +const VALID_AES_KEY_BYTES = [16, 24, 32]; +const AES_IV_BYTES = 16; + +const validateAesConfig = () => { + const validKey = VALID_AES_KEY_BYTES.includes(KEY.sigBytes); + const validIv = IV.sigBytes === AES_IV_BYTES; + + if (validKey && validIv) return; + + const message = [ + "AES 설정이 올바르지 않습니다.", + `KEY: ${KEY.sigBytes} bytes (허용: ${VALID_AES_KEY_BYTES.join(", ")})`, + `IV: ${IV.sigBytes} bytes (필수: ${AES_IV_BYTES})`, + ].join("\n"); + + if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_ENV === "local") { + const w = window as Window & { __kfpaCryptoConfigAlerted?: boolean }; + if (!w.__kfpaCryptoConfigAlerted) { + w.__kfpaCryptoConfigAlerted = true; + alert(message); + } + } +}; + +validateAesConfig(); export type WordArray = CryptoJS.lib.WordArray;