在python中将256位哈希拆分为32位前缀
在 python 中,如何将 SHA256 哈希拆分为 32 位前缀?我正在使用 Google 的安全浏览 api,这要求我比较我自己的集合和 API 发送给我的集合之间的 32 位前缀。我了解如何从 Google 中提取列表,并且了解如何从解析的 URL 形成哈希值集合,但是,我不明白如何导出每个哈希值的前 32 位。
获得前缀后,最好的做法是将它们放入字典中,相应的键/值对是前缀/完整哈希,以便我稍后可以引用它们?
In python, how does one split a SHA256 hash into a 32bit prefixes? I'm working with Google's safebrowsing api, which requires that I compare 32bit prefixes between my own collection, and the collection the API sends to me. I understand how to pull the list from Google, and I understand how to form a collection of hashes from parsed URLs, however, I don't understand how I am to derive the first 32bits of each hash.
And after obtaining the prefix, would the best course of action between to place them in a dictionary with corresponding key/value pairs being the prefix/full hash, so that I can reference them later?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
32 位是前 4 个字节。所以你可以对字节数组进行切片。
您可以将其用作字典键。
编辑
我不确定您是否需要十六进制表示形式。
32 bits is the first 4 bytes. So you can slice the byte array.
You can take that and use it as a dictionary key.
EDIT
I'm not sure if you need the hex representation, that would be.