Error trying to encrypt with BCRYPT in Python

0

Code:

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

error:

  

TypeError: Unicode-objects must be encoded before hashing

When running the program, you have this error, how can I solve it?

    
asked by anonymous 15.05.2018 / 21:15

1 answer

1

The parameter must be of type bytes , you can call it in two ways, casting bytes

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

or by using an encoding:

hashed = bcrypt.hashpw('teste'.encode("utf-8"),bcrypt.gensalt())
    
15.05.2018 / 21:36