Fix backend TypeScript build errors
- Inline tsconfig.base.json settings into backend/tsconfig.json so the Docker build (which only copies backend/) can resolve them - Replace default imports of Node built-ins (crypto, net) with named imports - Replace default bcrypt import with named imports (compare, hash) - Switch @fastify/websocket from v8 to v7 (SocketStream API) to match Fastify v4 peer dependency; update WebSocket handler signatures accordingly - Remove obsolete `version` key from docker-compose.yml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import crypto from 'crypto';
|
||||
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto';
|
||||
|
||||
const ALGORITHM = 'aes-256-cbc';
|
||||
const IV_LENGTH = 16;
|
||||
|
||||
function getKey(): Buffer {
|
||||
const raw = process.env.ENCRYPTION_KEY || '';
|
||||
// Derive exactly 32 bytes from whatever key string is provided
|
||||
return crypto.createHash('sha256').update(raw).digest();
|
||||
return createHash('sha256').update(raw).digest();
|
||||
}
|
||||
|
||||
export function encrypt(text: string): string {
|
||||
const iv = crypto.randomBytes(IV_LENGTH);
|
||||
const cipher = crypto.createCipheriv(ALGORITHM, getKey(), iv);
|
||||
const iv = randomBytes(IV_LENGTH);
|
||||
const cipher = createCipheriv(ALGORITHM, getKey(), iv);
|
||||
const encrypted = Buffer.concat([cipher.update(text, 'utf8'), cipher.final()]);
|
||||
return `${iv.toString('hex')}:${encrypted.toString('hex')}`;
|
||||
}
|
||||
@@ -20,7 +19,7 @@ export function decrypt(encryptedText: string): string {
|
||||
const [ivHex, encryptedHex] = encryptedText.split(':');
|
||||
const iv = Buffer.from(ivHex, 'hex');
|
||||
const encrypted = Buffer.from(encryptedHex, 'hex');
|
||||
const decipher = crypto.createDecipheriv(ALGORITHM, getKey(), iv);
|
||||
const decipher = createDecipheriv(ALGORITHM, getKey(), iv);
|
||||
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
||||
return decrypted.toString('utf8');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user