【问题标题】:TypeError: Strings must be encoded before hashing in PythonTypeError:字符串必须在 Python 中进行散列之前进行编码
【发布时间】:2022-12-05 04:05:04
【问题描述】:

我试图修复这段代码并解决它的错误,但不幸的是没有得到哪个部分有问题。

import hashlib 

for passwd in open("rockyou.txt", "r"):    
    if hashlib.md5(passwd.strip() + "yhbG").hexdigest() == "f2b31b3a7a7c41093321d0c98c37f5ad":        
        print ("[+] password for Collins Hackle is {}").format(passwd.strip())        
        exit(0) 
print ("[+] Done")

当我这样做时,显示以下错误:

Traceback (most recent call last):
  File "C:\Users\golno\OneDrive\Desktop\test.py", line 6, in <module>
    if hashlib.md5(passwd.strip() + "yhbG").hexdigest() == "f2b31b3a7a7c41093321d0c98c37f5ad":
TypeError: Strings must be encoded before hashing

应该更改哪部分代码?

我尝试帮助Python 3.3 - Unicode-objects must be encoded before hashing,但没有解决。

【问题讨论】:

  • hashlib.md5 不接受字符串作为参数。您需要传入 my_string.encode() 的结果(或您的字符串变量是什么)。链接的问题实际上告诉你如何解决它。

标签: python python-3.x encoding syntax-error hashlib


【解决方案1】:

你在文件打开和读取之前循环?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 2019-07-16
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多