小编use*_*683的帖子

如何在Python中使用sha256哈希

我想读一个密码文件.然后我尝试计算每个密码的哈希值,并将其与我已经拥有的哈希值进行比较,以确定我是否发现了密码.但是我不断得到的错误消息是"TypeError:必须在散列之前对Unicode对象进行编码".这是我的代码:

from hashlib import sha256

with open('words','r') as f:
    for line in f:

        hashedWord = sha256(line.rstrip()).hexdigest()

        if hashedWord == 'ca52258a43795ab5c89513f9984b8f3d3d0aa61fb7792ecefe8d90010ee39f2':
            print(line + "is one of the words!")
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙并提供解释吗?

python sha256

15
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×1

sha256 ×1