php hash_hmac(SHA512)to python new HMAC()

发布于 2025-02-01 08:30:33 字数 530 浏览 3 评论 0原文

PHP代码

    function get_signature($data, $secret_key) {
        $algo = "sha512";
        $result = hash_hmac(
            $algo,
            $data,
            $secret_key,
            false
        );

        return $result;
}

Python代码(尝试)

def get_signature(data, secret_key):
    signature = hmac.new(secret_key.encode(), data.encode(), hashlib.sha512).hexdigest()
    print(signature)

    return signature

Hashed值不同。 如何从Python代码中获得与PHP代码相同的值?

谢谢!

php code

    function get_signature($data, $secret_key) {
        $algo = "sha512";
        $result = hash_hmac(
            $algo,
            $data,
            $secret_key,
            false
        );

        return $result;
}

python code (Tried)

def get_signature(data, secret_key):
    signature = hmac.new(secret_key.encode(), data.encode(), hashlib.sha512).hexdigest()
    print(signature)

    return signature

the hashed value is not same.
how can I get same value as in php code from python code?

thanks!

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

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

发布评论

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

评论(1

原来分手还会想你 2025-02-08 08:30:33

该代码正常工作。
问题是在另一个代码上。

the code is working properly.
the issue was on another code.

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