密钥128位,返回数组16位

我详细介绍了这个项目:我为mega.co.nz使用了一个PHP SDK,但是由于密码学的问题(prepare_key太慢了,偶尔会导致一个我形容为“false positive”的问题)为了login,经过多次testing(python,c ++,c#)没有经验,我在nodejs中发现了一个sdk,无法适应我的需求。

该SDK是https://github.com/tonistiigi/mega/和问题是下一个:

Node.JS返回一个16字节的数组,而PHP返回4个字(每个4字节)

例

如何将数组转换为nodejs,否则返回?

对不起我的英语不好!!

从node.js转换为PHP格式:

buffer = require('buffer'); arr = [8,24,40,56,72,88,104,120,136,152,168,184,200,216,232,248]; console.log(arr.length); buff = new Buffer(arr); console.log(buff); phpstreq = []; phpinteq = []; length = 4; count = 0; while (count < 16) { phpinteq.push(buff.readUInt32BE(count,true)) phpstreq.push(buff.slice(count,count+length)); count += length; } console.log(phpinteq); console.log(phpstreq); 

上面的输出

 [ 135800888, 1213753464, 2291706040, 3369658616 ] [ <Buffer 08 18 28 38>, <Buffer 48 58 68 78>, <Buffer 88 98 a8 b8>, <Buffer c8 d8 e8 f8> ] 

从PHP转换为node.js格式:

 <?php $arr = [ 135800888, 1213753464, 2291706040, 3369658616 ]; $bytearray =[]; foreach ($arr as $byte4) { $eq = unpack("C*", pack("N", $byte4)); $bytearray = array_merge($bytearray,$eq); } print_r($bytearray); ?> 

产量

 Array ( [0] => 8 [1] => 24 [2] => 40 [3] => 56 [4] => 72 [5] => 88 [6] => 104 [7] => 120 [8] => 136 [9] => 152 [10] => 168 [11] => 184 [12] => 200 [13] => 216 [14] => 232 [15] => 248 ) 

我使用了上面的big endian格式。 既然你模糊你的输出,你将不得不自己检查。 另外要注意的是,你要validationnode.js中使用的input数组。 在node.js中,数组中的整数x必须是0 < x < 256 (记住每个数字= 1个字节)。