Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Strings must be encoded before hashing

Tags:

python-3.9

On this code:


##script qui brute force les hashs

import hashlib

while True :
    try : 
        wordlist_user = input("entrez votre wordlist:  ")
        wordlist = open(wordlist_user, "r", encoding='utf-8')
        hash = input('entrez le hash que vous oulez cracker (sha224) : ')
        break

    except :
     print('Error')



for word in wordlist.readlines():
    word = word.strip()
    wordlist_hash = hashlib.sha224(word).hexdigest()

    if (hash == wordlist_hash):
        print('password trouve: ' +word)
    else :
        print('password non trouve')

I have this error

wordlist_hash = hashlib.sha224(word).hexdigest() TypeError: Strings must be encoded before hashing

can someone help me ?

like image 205
Ayoub.A Avatar asked Mar 29 '26 19:03

Ayoub.A


1 Answers

hashlib.sha224() takes bytes but word is a string. You'll want to convert the string to the utf-8 encoded bytes with word.encode(encoding = 'UTF-8', errors = 'strict')

like image 171
Kelly Avatar answered Apr 01 '26 08:04

Kelly