I use this code to crypt/decrypt string value
var crypto = require(\'crypto\');
function encrypt(text){
var cipher = crypto.createCipher(\'aes-256-cbc\'
I also faced the same issue. I had to go through all the comments to check for answer and @Alexey Ten's comment helped me. So in order to make @Alexey Ten's answer more visible below are the changes.
var crypto = require('crypto');
function encrypt(text){
try{
var cipher = crypto.createCipher('aes-256-cbc','secret key');
var encrypted = cipher.update(text.toString(),'utf8','hex') + cipher.final('hex');
return encrypted;
} catch(exception) {
throw exception;
}
}
function decrypt(text){
try{
var decipher = crypto.createDecipher('aes-256-cbc','secret key');
var decrypted = decipher.update(text.toString(),'hex','utf8') + decipher.final('utf8');
return decrypted ;
} catch(exception) {
throw exception;
}
}