Updated encryption

This commit is contained in:
Keith Holliday
2018-01-25 17:33:50 -06:00
parent d85f18751c
commit 3fcd04fd8a
2 changed files with 11 additions and 7 deletions

View File

@@ -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;
}