Hash Functions - Examples
In this section we shall provide a few examples about calculating cryptographic hash functions in Python.
Calculating Cryptographic Hash Functions in Python
We shall use the standard Python library 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:
The expected output from the above example looks like this:
Now write some Python code to calculate a Keccak-256 hash:
The output from the above examples is:
Last updated
Was this helpful?