Node.js crypto createDecipher()

Description

Node.js crypto createDecipher()


var crypto = require('crypto'),
    algorithm = 'aes-256-ctr',
    password = 'd6F3Efeq';
 
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;//  w  w w.  ja va  2  s. c  o  m
}
word = "asdfasdfasdf';.sdg";
var hw = encrypt(word)
// outputs hello world
console.log(hw);
console.log(word.length);
console.log(hw.length);
console.log(decrypt(hw));



PreviousNext

Related