This module implements the HMAC algorithm, as described by RFC 2104 (https://tools.ietf.org/html/rfc2104.html). Since it is very small, but nonetheless important, I will provide you with a simple example:
# hmc.py
import hmac
import hashlib
def calc_digest(key, message):
key = bytes(key, 'utf-8')
message = bytes(message, 'utf-8')
dig = hmac.new(key, message, hashlib.sha256)
return dig.hexdigest()
digest = calc_digest('secret-key', 'Important Message')
As you can see, the interface is always the same or similar. We first convert the key and the message into bytes, and then create a digest instance that we will use to get a hexadecimal representation of the hash. Not much else to say, but I thought to add this module anyway, for completeness.
Now, let's move on to a different type of token: JWTs.