如何在飞镖上使用同一SHA256ENCRIPT.PHP编码?

发布于 2025-02-07 18:44:10 字数 1038 浏览 1 评论 0 原文

我在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);

在飞镖上进行编码?

谢谢!

I have this class on 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;
    }
}

And I need to do exactly the same on flutter, using .dart.
I tried:

    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 

And how to code

$string .= str_pad(strtolower(dechex($hashedArray[$i])), 2, '0', STR_PAD_LEFT);

on dart?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

貪欢 2025-02-14 18:44:10

循环的PHP只是编码为十六进制,对吗?

DART中有一个十六进制编解码器, convert package package(注意:不是 dart:convert )。将其添加到pubspec.yaml,将其导入到源文件的顶部,然后:

final hexString = hex.encode(hashedArray);

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:

final hexString = hex.encode(hashedArray);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文