Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Use encryption key for apikeys

Khuram Niazf63a975d4243
diff --git a/.env.example b/.env.example
index ecd2cc6..d281c1d 100644
--- a/.env.example
+++ b/.env.example
@@ -12,6 +12,11 @@ NEXTAUTH_URL=http://localhost:3000
# To set manually, uncomment and provide your own value:
# AUTH_SECRET=
+# ENCRYPTION_KEY is used to encrypt stored API keys (OpenAI, DeepSeek, RapidAPI)
+# Must be stable across restarts — changing it will make all stored API keys unrecoverable
+# Generate with: openssl rand -base64 32
+# ENCRYPTION_KEY=
+
OPENAI_API_KEY=your-openai-api-key-here
# DeepSeek API Key - get from https://platform.deepseek.com
diff --git a/docker-compose.yml b/docker-compose.yml
index 82867a3..8aeac49 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,6 +10,7 @@ services:
- NODE_ENV=production
- DATABASE_URL=file:/data/dev.db
- AUTH_SECRET=${AUTH_SECRET:-}
+ - ENCRYPTION_KEY=you-encryption-key-here
- NEXTAUTH_URL=${NEXTAUTH_URL:-http://localhost:3000}
- AUTH_TRUST_HOST=${AUTH_TRUST_HOST:-true}
- TZ=${TZ:-America/Edmonton}
diff --git a/src/lib/encryption.ts b/src/lib/encryption.ts
index bcc7cb1..9d1334b 100644
--- a/src/lib/encryption.ts
+++ b/src/lib/encryption.ts
@@ -1,6 +1,11 @@
import "server-only";
-import { createCipheriv, createDecipheriv, randomBytes, pbkdf2Sync } from "crypto";
+import {
+ createCipheriv,
+ createDecipheriv,
+ randomBytes,
+ pbkdf2Sync,
+} from "crypto";
const ALGORITHM = "aes-256-gcm";
const IV_LENGTH = 12;
@@ -10,9 +15,9 @@ const PBKDF2_ITERATIONS = 100_000;
const SALT = "jobsync-api-key-encryption";
function getDerivedKey(): Buffer {
- const secret = process.env.AUTH_SECRET;
+ const secret = process.env.ENCRYPTION_KEY;
if (!secret) {
- throw new Error("AUTH_SECRET is not set");
+ throw new Error("ENCRYPTION_KEY is not set");
}
return pbkdf2Sync(secret, SALT, PBKDF2_ITERATIONS, KEY_LENGTH, "sha256");
}
@@ -20,7 +25,9 @@ function getDerivedKey(): Buffer {
export function encrypt(plaintext: string): { encrypted: string; iv: string } {
const key = getDerivedKey();
const iv = randomBytes(IV_LENGTH);
- const cipher = createCipheriv(ALGORITHM, key, iv, { authTagLength: AUTH_TAG_LENGTH });
+ const cipher = createCipheriv(ALGORITHM, key, iv, {
+ authTagLength: AUTH_TAG_LENGTH,
+ });
let encrypted = cipher.update(plaintext, "utf8", "base64");
encrypted += cipher.final("base64");
@@ -47,7 +54,9 @@ export function decrypt(encryptedData: string, iv: string): string {
const authTag = combined.subarray(combined.length - AUTH_TAG_LENGTH);
const encrypted = combined.subarray(0, combined.length - AUTH_TAG_LENGTH);
- const decipher = createDecipheriv(ALGORITHM, key, ivBuffer, { authTagLength: AUTH_TAG_LENGTH });
+ const decipher = createDecipheriv(ALGORITHM, key, ivBuffer, {
+ authTagLength: AUTH_TAG_LENGTH,
+ });
decipher.setAuthTag(authTag);
let decrypted = decipher.update(encrypted);