# 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)}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Function: hash.compute_hmac\n\nComputes the hash-based message authentication code (HMAC) for data given a secret key and hashing algorithm.\n\nArguments\n---------\n\nReturns\n-------\n\nThe computed HMAC hash in bytes.\n\nRaised exceptions\n-----------------\n\nExamples\n--------\n\nFor more information, see\n[Returning bytes](https://cloud.google.com/workflows/docs/reference/syntax/datatypes.md#bytes). \n\n```yaml\n# Compute HMAC SHA-256 hash for message (bytes) using a secret key (bytes)\n- assignStep:\n assign:\n - keyBytes: ${text.encode(\"key\", \"UTF-8\")}\n - dataBytes: ${text.encode(\"Hello World\", \"UTF-8\")}\n - algorithmName: \"SHA256\"\n # Compute HMAC SHA-256 hash for data in bytes\n - hmac: ${hash.compute_hmac(keyBytes, dataBytes, algorithmName)}\n- returnStep:\n # Return HMAC encoded to Base64 string: \"QidPcoCDkuWLV9co1+PA5RY+rwfRZdwDEF9iq74afRE=\"\n return: ${base64.encode(hmac)}\n```"]]