Macos nodejs密码ubuntu未按预期工作
我写了一个数据加密工具,它可以在mac os上运行,但不能在ubuntu上运行。 下面的代码显示了差异Macos nodejs密码ubuntu未按预期工作,macos,node.js,ubuntu,cryptography,encryption,Macos,Node.js,Ubuntu,Cryptography,Encryption,我写了一个数据加密工具,它可以在mac os上运行,但不能在ubuntu上运行。 下面的代码显示了差异 var crypto = require('crypto'); var k = '1234567890123456'; var v = '1234567890123456'; var alg = 'AES-128-CBC'; var buf = new Buffer('Hello world!'); console.log(buf); var cipher = crypto.creat
var crypto = require('crypto');
var k = '1234567890123456';
var v = '1234567890123456';
var alg = 'AES-128-CBC';
var buf = new Buffer('Hello world!');
console.log(buf);
var cipher = crypto.createCipheriv(alg, k, v);
var result = cipher.update(buf);
result += cipher.final();
buf = new Buffer(result, 'binary');
console.log(buf);
var decipher = crypto.createDecipheriv(alg, k, v);
decipher.setAutoPadding(auto_padding=false);
result = decipher.update(buf);
result += decipher.final();
buf = new Buffer(result, 'binary');
console.log(buf);
console.log(buf.toString());
mac上的输出:
<Buffer 48 65 6c 6c 6f 20 77 6f 72 6c 64 21>
<Buffer 17 0e 2d 73 94 bf d4 24 95 b3 a7 49 73 58 5e 3f>
<Buffer 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 04 04 04 04>
Hello world!
你好,世界!
ubuntu:
<Buffer 48 65 6c 6c 6f 20 77 6f 72 6c 64 21>
<Buffer 17 0e 2d 73 fd fd fd 24 fd fd fd 49 73 58 5e 3f>
<Buffer 05 6d 69 fd fd 1b 49 62 60 39 fd 68 fd fd fd>
mi��Ib`9�h���
惯性矩��Ib`9�H���
有什么想法吗?thx节点0.10.0对加密模块进行了一些内部更改,这可能会破坏现有代码 通过以下修复(如建议的),它可以在我的Debian机器上运行: (感谢@user568109让我阅读了这一页!)
上面提到的页面还建议永久修复代码,因为设置
加密。默认编码被认为是一种临时措施。我无法在ubuntu中重现。我正在运行Ubuntu12.04,节点0.8,这里一切都很好。您的系统设置是什么?我可以在Debian上使用node 0.10.0在i386和x86_64平台上复制它。听起来它可能是一个过时的OpenSSL库(我的两台机器都不是最新的)。上次我检查crypto API页面时,它是3-稳定的,但现在页面显示为稳定性:2-不稳定。因此,您应该使用节点0.8,或者等到节点稳定后再使用。user568109谢谢!我的节点版本是v0.10.0和ubuntu12.04。当robertklep运动时,设置crypto.DEFAULT_编码后,它就会工作。(刚刚检查,原始代码在Mac上的节点0.10.0也会失败)
var crypto = require('crypto');
crypto.DEFAULT_ENCODING = 'binary';
...