【发布时间】:2020-06-14 01:41:48
【问题描述】:
我正在尝试对通过 easygui 输入的用户输入进行哈希处理。 Easygui 将输入存储到一个数组中(我认为),所以当我尝试对用户输入进行哈希处理时,我不确定如何将其变成一个字节。
这是我的代码:
import hashlib
import easygui
g = hashlib.sha256(b'helloworld').hexdigest()
l = easygui.enterbox('enter password')
f = hashlib.sha256([l]).hexdigest()
print(g)
print(f)
理想情况下,如果我在 easygui 中键入“helloworld”,它应该返回相同的散列输出。
目前的错误是:
"TypeError: object supporting the buffer API required" at the line f = haslib.sha256([l]).hexdigest()
【问题讨论】:
-
你为什么用 list(
[l]) 包裹l?我不知道easygui,但你可以试试hashlib.sha256(l)而不是hashlib.sha256([l])。 -
你可以试试
hashlib.sha256('helloworld'.encode())
标签: python python-3.x hash hashlib