如何在飞镖上使用同一SHA256ENCRIPT.PHP编码?
我在PHP上有这个课程:
{
public function Generate($ipAddress, $secretKey, $comercio, $sucursal, $amount)
{
$input = sprintf("%s*%s*%s*%s*%s", $ipAddress, $comercio, $sucursal, $amount, $secretKey);
$inputArray = utf8_encode($input);
$hashedArray = unpack('C*', hash( "sha256", $inputArray, true));
$string = null;
for ($i = 1; $i <= count($hashedArray); $i++) {
$string .= str_pad(strtolower(dechex($hashedArray[$i])), 2, '0', STR_PAD_LEFT);
}
return $string;
}
}
我需要在Flutter上使用.dart进行完全相同的操作。 我尝试了:
var input = ("$ipAddress*$secretKey*$comercio*$sucursal*$amount");
var inputArray = utf8.encode(input); // I get an array with numbers here, while in php
// I get the same string
var hashedArray = sha256.convert(inputArray); //need unpack
如何
$string .= str_pad(strtolower(dechex($hashedArray[$i])), 2, '0', STR_PAD_LEFT);
在飞镖上进行编码?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
循环的PHP只是编码为十六进制,对吗?
DART中有一个十六进制编解码器, convert package package(注意:不是
dart:convert)。将其添加到pubspec.yaml,将其导入到源文件的顶部,然后:
That php for loop is just encoding into hex, right?
There's a hex codec in Dart, in the convert package (note: not
dart:convert
). Add that to pubspec.yaml, import it at the top of your source file, then: