mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Updated encryption
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
"CRON_SEMI_SAFE_MODE":"false",
|
||||
"MAINTENANCE_MODE": "false",
|
||||
"SESSION_SECRET":"YOUR SECRET HERE",
|
||||
"SESSION_SECRET_KEY": "1234567891234567891234567891234567891234567891234567891234567891",
|
||||
"SESSION_SECRET_IV": "12345678912345678912345678912345",
|
||||
"ADMIN_EMAIL": "you@example.com",
|
||||
"SMTP_USER":"user@example.com",
|
||||
"SMTP_PASS":"password",
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import {
|
||||
createCipher,
|
||||
createDecipher,
|
||||
createCipheriv,
|
||||
createDecipheriv,
|
||||
} from 'crypto';
|
||||
import nconf from 'nconf';
|
||||
|
||||
const algorithm = 'aes-256-ctr';
|
||||
const SESSION_SECRET = nconf.get('SESSION_SECRET');
|
||||
const SESSION_SECRET_KEY = nconf.get('SESSION_SECRET_KEY');
|
||||
const SESSION_SECRET_IV = nconf.get('SESSION_SECRET_IV');
|
||||
|
||||
const key = Buffer.from(SESSION_SECRET_KEY, 'hex');
|
||||
const iv = Buffer.from(SESSION_SECRET_IV, 'hex');
|
||||
|
||||
export function encrypt (text) {
|
||||
let cipher = createCipher(algorithm, SESSION_SECRET);
|
||||
const cipher = createCipheriv(algorithm, key, iv);
|
||||
let crypted = cipher.update(text, 'utf8', 'hex');
|
||||
|
||||
crypted += cipher.final('hex');
|
||||
return crypted;
|
||||
}
|
||||
|
||||
export function decrypt (text) {
|
||||
let decipher = createDecipher(algorithm, SESSION_SECRET);
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
let dec = decipher.update(text, 'hex', 'utf8');
|
||||
|
||||
dec += decipher.final('utf8');
|
||||
return dec;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user