Files
yourpart3/backend/utils/crypto.js
Torsten Schulz (local) 6da849ca3c feat: Einführung von Umgebungsvariablen und Startskripten für die Backend-Anwendung
- Hinzufügen eines zentralen Skripts zum Laden von Umgebungsvariablen aus einer .env-Datei.
- Implementierung von Start- und Entwicklungs-Skripten in der package.json für eine vereinfachte Ausführung der Anwendung.
- Bereinigung und Entfernung nicht mehr benötigter Minigame-Modelle und -Services zur Verbesserung der Codebasis.
- Anpassungen an den Datenbankmodellen zur Unterstützung von neuen Assoziationen und zur Verbesserung der Lesbarkeit.
2025-08-23 22:27:19 +02:00

23 lines
886 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import crypto from 'crypto';
const algorithm = 'aes-256-ecb'; // Verwende ECB-Modus, der keinen IV benötigt
const secret = process.env.SECRET_KEY;
if (!secret) {
console.warn('[crypto] SECRET_KEY fehlt verwende unsicheren Fallback (nur Entwicklung).');
}
const key = crypto.scryptSync(secret || 'DEV_FALLBACK_SECRET', 'salt', 32); // Der Schlüssel sollte eine Länge von 32 Bytes haben
export const encrypt = (text) => {
const cipher = crypto.createCipheriv(algorithm, key, null); // Kein IV verwendet
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
};
export const decrypt = (text) => {
const decipher = crypto.createDecipheriv(algorithm, key, null); // Kein IV verwendet
let decrypted = decipher.update(text, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
};