Files
2017-06-27 21:59:40 +10:00

18 lines
475 B
JavaScript

import crypto from 'crypto';
const algorithm = 'aes-256-ctr';
export function encrypt(obj, key){
const cipher = crypto.createCipher(algorithm, key);
return cipher.update(JSON.stringify(obj), 'utf8', 'hex') + cipher.final('hex');
}
export function decrypt(text, key){
var decipher = crypto.createDecipher(algorithm, key)
try{
return JSON.parse(decipher.update(text,'hex','utf8') + decipher.final('utf8'));
}catch(err){
return {}
}
}