hashlib. The input data for hashing should be given as bytes sequence (bytes object), so we need to encode the input string using some text encoding, e.g.
utf8. The produced output data is also a bytes sequence, which can be printed as hex digits using
binascii.hexlify()as shown below:
Keccak-256hashes (the hash function used in the Ethereum blockchain) requires non-standard Python functions. In the below example we use the
pycryptodomepackage available from PyPI: https://pypi.org/project/pycryptodome.