我正在尝试构建一个用于练习的 md5 cookies 。在我继续之前,这里是我的代码:
def offline_wordlist_attack(list_path):
with fileinput.input(files=(list_path)) as wordlist:
for word in wordlist:
md5_hash_object = hashlib.md5() # constructing an md5 hash object
md5_hash_object.update(binascii.a2b_uu(word))
word_digest = md5_hash_object.digest() # performing the md5 digestion of the word
print(word_digest) # Debug
我的问题是
md5_hash_object.update(binascii.a2b_uu(word))
. hashlib Python 3 文档指出传递给 update()
的字符串应该在 二进制表示 .文档使用 m.update(b"Nobody inspects")
举个例子。在我的代码中,我不能简单地附加 b
前面的变量word
.所以我尝试使用 binascii库,但该库也在文档中注明:Note
Encoding and decoding functions do not accept Unicode strings. Only bytestring and bytearray objects can be processed.
有人可以帮我解决这个问题吗?它让我变得更好。
最佳答案
您需要传入一个 bytes
对象,而不是 str
.从 str
出发的典型路线(Python 3 中的 unicode 字符串)到 bytes
是使用 .encode()
方法并指定您希望使用的编码。
my_bytes = my_string.encode('utf-8')
关于binary - 如何在python中对字符串进行二进制编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12175417/