Function: hash.compute_checksum

Computes checksum using a given hashing algorithm.

Arguments

Arguments
data

bytes

The input to compute checksum for.

algorithm

string

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

Returns

The computed checksum in bytes.

Raised exceptions

Exceptions
TypeError If data is 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 SHA-256 checksum of a message (bytes) and return it as a Base64 string
- assignStep:
    assign:
      - dataBytes: ${text.encode("Hello World", "UTF-8")}
      - algorithmName: "SHA256"
      # Compute SHA-256 checksum of data in bytes
      - checksum: ${hash.compute_checksum(dataBytes, algorithmName)}
- returnStep:
    # Return checksum encoded to Base64 string: "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4="
    return: ${base64.encode(checksum)}