Key Derivation
Bcrypt
Using Bcrypt in Python
from base64 import b64encode
from Crypto.Hash import SHA256
from Crypto.Protocol.KDF import bcrypt
password = b"secret"
b64pwd = b64encode(SHA256.new(password).digest())
bcrypt_hash = bcrypt(b64pwd, 12)
print(f"hash: {bcrypt_hash}")from base64 import b64encode
from Crypto.Hash import SHA256
from Crypto.Protocol.KDF import bcrypt, bcrypt_check, _bcrypt_hash
password = b"secret"
# Specify the hash generated
bcrypt_hash = b"$2a$12$F86jMkaNbEm8lPm6q6zbCuiIGOAsz4azBZkAeSalFYXjctIjiQG1C"
try:
b64pwd = b64encode(SHA256.new(password).digest())
bcrypt_check(b64pwd, bcrypt_hash)
print("Password is correct")
except ValueError:
print("Incorrect password")References
Last updated