How to correct TypeError: Unicode-objects must be encoded before hashing?
It is probably looking for a character encoding from
wordlistfile = open(wordlist,"r",encoding='utf-8')
Or, if you're working on a line-by-line basis:
Per the comment below and this answer.
My answer above assumes that the desired output is a
str from the
wordlist file. If you are comfortable in working in
bytes, then you're better off using
open(wordlist, "rb"). But it is important to remember that your
hashfile should NOT use
rb if you are comparing it to the output of
hashlib.md5(value).hashdigest() outputs a
str and that cannot be directly compared with a bytes object:
'abc' != b'abc'. (There's a lot more to this topic, but I don't have the time ATM).
It should also be noted that this line:
Should probably be
That will work for both bytes and str's. But if you decide to simply convert to
bytes, then you can change the line to:
You must have to define
encoding format like
utf-8, Try this easy way,
This example generates a random number using the SHA256 algorithm:
import hashlib hashlib.sha256(str(random.getrandbits(256)).encode('utf-8')).hexdigest()'cd183a211ed2434eac4f31b317c573c50e6c24e3a28b82ddcb0bf8bedf387a9f'