修改: app/utils/encryption.ts

This commit is contained in:
glay 2024-11-06 00:43:03 +08:00
parent cae20af24d
commit ca17e90c52

View File

@ -1,7 +1,13 @@
import { AES, enc } from "crypto-js"; 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 { export function encrypt(data: string): string {
try { try {
return AES.encrypt(data, SECRET_KEY).toString(); return AES.encrypt(data, SECRET_KEY).toString();