Function: hash.compute_hmac

Computes the hash-based message authentication code (HMAC) for data given a secret key and hashing algorithm.

Arguments

Arguments
key

bytes

The secret key to use when computing HMAC hash.

data

bytes

The input to compute HMAC for.

algorithm

string

The hashing algorithm to use when computing HMAC hash. Supported algorithms: MD5, SHA1, SHA224, SHA256, SHA384, SHA512.

Returns

The computed HMAC hash in bytes.

Raised exceptions

Exceptions
TypeError If key and data are not in bytes, or if algorithm is not a string.
ValueError If the provided hashing algorithm is not supported.

Examples

For more information, see Returning bytes.

# Compute HMAC SHA-256 hash for message (bytes) using a secret key (bytes)
- assignStep:
    assign:
      - keyBytes: ${text.encode("key", "UTF-8")}
      - dataBytes: ${text.encode("Hello World", "UTF-8")}
      - algorithmName: "SHA256"
      # Compute HMAC SHA-256 hash for data in bytes
      - hmac: ${hash.compute_hmac(keyBytes, dataBytes, algorithmName)}
- returnStep:
    # Return HMAC encoded to Base64 string: "QidPcoCDkuWLV9co1+PA5RY+rwfRZdwDEF9iq74afRE="
    return: ${base64.encode(hmac)}