Skip to content

Instantly share code, notes, and snippets.

@shamsher31
Created August 19, 2015 14:13
Show Gist options
  • Save shamsher31/b9d6cad0295c837d200e to your computer and use it in GitHub Desktop.
Save shamsher31/b9d6cad0295c837d200e to your computer and use it in GitHub Desktop.
Encrypt and Decrypt using crypto nodejs
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = '6LehWQcTAAAAADgH-I5WmmkuDFFJ_pMr_866zz17';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var hw = encrypt("x-timezone")
// outputs hello world
console.log(hw);
console.log(decrypt(hw));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment