I am writing a node.js application where I use Mycrypt (https://www.npmjs.org/package/mcrypt) however I am getting a segmentation fault when I try to encrypt a string. I am running on CentOS. The code is below:
exports.encode = function (string, callback) {
var key = Crypto.MD5(Constants.ENCRYPTION_KEY).toString(Crypto.enc.Hex);
var rijCbc = new MCrypt('rijndael-256', 'cbc');
rijCbc.open(key);
var buffer = new Buffer(string, 'base64');
var enc = rijCbc.encrypt(buffer); // this line is causing a segmentation fault
var rtn = enc.toString();
rtn = rtn.replace('+','-b0221');
rtn = rtn.replace('^','-b1121');
rtn = rtn.replace('!','-b1427');
rtn = rtn.replace('*','-b1225');
rtn = rtn.replace('&','-b4422');
rtn = rtn.replace('@','-b4252');
rtn = rtn.replace('%','-b6422');
rtn = rtn.replace('=','-b0123t');
rtn = rtn.replace('/','-b0169');
rtn = rtn.replace('\\','-b4236');
callback(rtn);
}
You can also find the Mcrypt.encrypt() function here: https://github.com/tugrul/node-mcrypt/blob/master/src/mcrypt.cc Any idea why this is happening?