php - key 128 位,返回数组 16 位

标签 php arrays node.js

我详细介绍了该项目: 我正在使用 mega.co.nz 的 PHP SDK,但由于加密问题(prepare_key 太慢,有时会导致我描述为“误报”的问题),我寻找登录的替代方案,在没有经验的情况下进行了多次测试替代方案(python、c++、c#)后,我在 nodejs 中找到了一个 sdk,但无法适应我的需求。

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

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

Example

如何将数组转换为将我返回到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
)

我在上面使用了大端格式。由于您模糊了输出,因此您必须自己检查。另请注意验证 node.js 中使用的输入数组。在node.js中整数x数组中必须是 0 < x < 256 (记住每个数字 = 1 个字节)。

关于php - key 128 位,返回数组 16 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948021/

相关文章:

java - 从android在线数据库中插入数据

php - fsockopen-如何检测消息结束?

php - 两个图像按钮或两个提交

java - 表达式的类型必须是数组类型但解析为 char

node.js - 用户与 Mongoose 的完美匹配

javascript - Mongoose 在对象数组中查找值

javascript - WebStorm,使用 Node Supervisor(所以每次代码更改后不必重新启动)?

php - jsonp -> json_decode()

arrays - 如何从由类中的函数组成的数组中删除一个项目?

javascript - 在 localStorage 中推送对象