fix(crypto): SHA-256 hash ENCRYPTION_KEY for AES-256-GCM

ENCRYPTION_KEY was 64 hex chars = 64 bytes. AES-256 needs exactly
32 bytes. Now hashing with SHA-256 to derive proper 32-byte key
regardless of input length. Fixed in auth.ts backfill encrypt
and wallet.ts encrypt/decrypt.
This commit is contained in:
2026-04-21 14:53:55 -04:00
parent 338e2a1fc1
commit 946b81384c
2 changed files with 170 additions and 153 deletions
+3 -6
View File
@@ -13,15 +13,12 @@ const TAUTULLI_API_KEY = process.env.TAUTULLI_API_KEY || "";
function encrypt(text: string): string {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(
"aes-256-gcm",
Buffer.from(ENCRYPTION_KEY),
iv,
);
const key = crypto.createHash("sha256").update(ENCRYPTION_KEY).digest();
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
let encrypted = cipher.update(text, "utf8", "hex");
encrypted += cipher.final("hex");
const authTag = cipher.getAuthTag();
return iv.toString("hex") + ":" + authTag.toString("hex") + ":" + encrypted;
return `${iv.toString("hex")}:${authTag.toString("hex")}:${encrypted}`;
}
const router = Router();