From ca17e90c52d3e3ba67dbca3ddcf7415b9fb3de90 Mon Sep 17 00:00:00 2001 From: glay Date: Wed, 6 Nov 2024 00:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20=20=20=20ap?= =?UTF-8?q?p/utils/encryption.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/encryption.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/utils/encryption.ts b/app/utils/encryption.ts index 0fb8439fe..76ceed68b 100644 --- a/app/utils/encryption.ts +++ b/app/utils/encryption.ts @@ -1,7 +1,13 @@ import { AES, enc } from "crypto-js"; -const SECRET_KEY = "your-secret-key"; // Replace this with a secure, randomly generated key - +const SECRET_KEY = + process.env.ENCRYPTION_KEY || + "your-secret-key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // Replace this with a secure, randomly generated key +if (!SECRET_KEY || SECRET_KEY.length < 32) { + throw new Error( + "ENCRYPTION_KEY environment variable must be set with at least 32 characters", + ); +} export function encrypt(data: string): string { try { return AES.encrypt(data, SECRET_KEY).toString();