import hmac
import hashlib
# Derive the key from password using PBKDF2-HMAC-SHA256 with 10,000 iterations
password = b'my password 12345'
salt = b'my salt'
iterations = 1000000
key = hashlib.pbkdf2_hmac('sha256', password, salt, iterations)
# Create an HMAC object using the derived key and the message
message = b'my message'
hmac_obj = hmac.new(key, message, digestmod=hashlib.sha256)
print(hmac_obj)
# Get the HMAC as a bytes
hmac_bytes = hmac_obj.digest()
print(hmac_bytes)
# Save the hmac for later verification
expected_hmac = hmac_bytes
print(expected_hmac)
# Verify the HMAC
# Create a new HMAC object using the derived key and the message
# test with incorrect message
message=b'BLUE'
verify_hmac_obj = hmac.new(key, message, digestmod=hashlib.sha256)
# Get the HMAC as a bytes
verify_hmac_bytes = verify_hmac_obj.digest()