def hmac(key, message, tag=None, alg=hashlib.sha256):
    """
    Generates a hashed message authentication code (HMAC) by prepending the
    specified @tag string to a @message, then hashing with to HMAC 
    using a cryptographic @key and hashing @alg -orithm.
    """
    return HMAC.new(str(key), str(tag) + str(message), digestmod=alg).digest()