如何使用 Python hashlib 或 zlib 在 crc32 中散列密钥和秘密消息?

How do I hash key and secret message in crc32 using Python hashlib or zlib?

import hashlib
import hmac
import base64

key = b'sdfgfcxc'
secret = b'?45$dfd*632sd!'
base64.b64encode(hmac.new(key, secret, hashlib.sha512).digest())

我想使用 crc32 算法散列相同的密钥和机密字段。但是,hashlib 不提供 crc32 散列。我相信我们可以使用 zlib 来应用 crc32 哈希,但是我如何结合密钥和秘密来使用 zlib 获取 crc32 哈希?还是 hashlib 本身提供了一些选项?

您可以简单地连接 keysecret 并使用 zlib.crc32() 计算该字节序列的 CRC-32。

但是,你确定这就是你想要的吗? hashlib 没有 CRC-32 是有原因的,因为它很容易被欺骗。即,提出具有相同散列的不同数据。