1

我正在编写一个使用 Mycrypt ( https://www.npmjs.org/package/mcrypt ) 的 node.js 应用程序,但是当我尝试加密字符串时出现分段错误。我在 CentOS 上运行。代码如下:

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);
}

您还可以在此处找到 Mcrypt.encrypt() 函数:https ://github.com/tugrul/node-mcrypt/blob/master/src/mcrypt.cc 知道为什么会这样吗?

4

0 回答 0