【问题标题】:PHP hash_hmac(sha512) to Python new hmac()PHP hash_hmac(sha512) 到 Python new hmac()
【发布时间】:2022-06-16 17:06:54
【问题描述】:

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

哈希值不相同。 如何从 python 代码中获得与 php 代码相同的值?

谢谢!

【问题讨论】:

  • 我看不出代码有什么问题。请创建一个minimal reproducible example,并附上密钥、数据和输出。
  • @Aran-Fey 非常感谢。我解决了问题。问题出在传递给数据的 json 中。

标签: python php hash hmac


【解决方案1】:

代码运行正常。 问题出在另一个代码上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-05-13
    • 1970-01-01
    • 2019-01-05
    相关资源
    最近更新 更多