feat: MakerWorld Login-Automatisierung mit persistentem Puppeteer-Profil und Code-Eingabe via App
This commit is contained in:
36
backend/src/crypto-helper.js
Normal file
36
backend/src/crypto-helper.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// ── Verschlüsselungs-Helper für sensible gespeicherte Zugangsdaten ──────────
|
||||
// Nutzt AES-256-GCM. Der Schlüssel wird aus JWT_SECRET abgeleitet (kein
|
||||
// zusätzlicher Env-Var nötig) — ausreichend für den Zweck hier (Zugangsdaten
|
||||
// liegen nicht mehr im Klartext in der SQLite-DB), ersetzt aber kein
|
||||
// dediziertes Secret-Management für hochsensible Fälle.
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
const KEY = crypto.createHash('sha256')
|
||||
.update(process.env.JWT_SECRET || 'dickendock-fallback-key-bitte-JWT_SECRET-setzen')
|
||||
.digest();
|
||||
|
||||
function encrypt(text) {
|
||||
const iv = crypto.randomBytes(12);
|
||||
const cipher = crypto.createCipheriv('aes-256-gcm', KEY, iv);
|
||||
const enc = Buffer.concat([cipher.update(String(text), 'utf8'), cipher.final()]);
|
||||
const tag = cipher.getAuthTag();
|
||||
return Buffer.concat([iv, tag, enc]).toString('base64');
|
||||
}
|
||||
|
||||
function decrypt(b64) {
|
||||
if (!b64) return null;
|
||||
try {
|
||||
const buf = Buffer.from(b64, 'base64');
|
||||
const iv = buf.subarray(0, 12);
|
||||
const tag = buf.subarray(12, 28);
|
||||
const enc = buf.subarray(28);
|
||||
const decipher = crypto.createDecipheriv('aes-256-gcm', KEY, iv);
|
||||
decipher.setAuthTag(tag);
|
||||
return Buffer.concat([decipher.update(enc), decipher.final()]).toString('utf8');
|
||||
} catch {
|
||||
return null; // falsches/verändertes Secret oder korrupte Daten
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { encrypt, decrypt };
|
||||
Reference in New Issue
Block a user