我写了一个数据加密工具,它适用于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.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���
任何的想法?谢谢