【发布时间】:2018-12-03 20:27:36
【问题描述】:
使用 digest() 方法的 sha512 哈希不等于 PHP 中使用 sha512 的 hash_hmac。
Python:
print base64.b64encode(hmac.new("key".encode("ascii"),"hello".encode("ascii"), hashlib.sha512).digest())
PHP:
<?php
echo base64_encode(hash_hmac('sha512', "hello", "key"));
?>
如果我在 python 中使用hexdigest() 方法代替digest() 方法,那么哈希结果是相同的。我需要使用digest()方法,那么php中是否有任何等效的方法可以得到相同的哈希结果?
【问题讨论】:
-
你比较过它们吗?区别在哪里?
-
我在 python 代码中用 hexdigest() 方法替换了 digest(),然后我将 Python 哈希结果与 php 哈希结果进行了比较。两者都是平等的。
标签: php python-3.x encryption hash