Im testing this encryption/decryption code found here. The code is:
var crypto = require('crypto');
var encrypt = function(text){
var algorithm = 'aes-256-ctr';
var password = 'gh6ttr';
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(JSON.stringify(text),'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
var decrypt = function(text){
var algorithm = 'aes-256-ctr';
var password = 'gh6ttr';
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(JSON.stringify(text),'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var encrypted = encrypt('test');
console.log('encrypted is ', encrypted);
var decrypted = decrypt(encrypted);
console.log('decrypted is ', decrypted);
The results are:
encrypted is 66b1f8423a42
decrypted is
decrypted is always blank. Any idea why this code doesn't work?