Error trying to encrypt with BCRYPT in Python

Asked

Viewed 67 times

0

Code:

import bcrypt
hashed = bcrypt.hashpw('teste',bcrypt.gensalt())

error:

Typeerror: Unicode-Objects must be encoded before hashing

Running the program shows this error, how can I fix?

1 answer

1


The parameter must be of the type bytes, you can call it two ways, giving a cast to bytes

hashed = bcrypt.hashpw(b'teste',bcrypt.gensalt())

or using an encoding:

hashed = bcrypt.hashpw('teste'.encode("utf-8"),bcrypt.gensalt())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.