Let us know so we can improve!
Handlebars Helper Function: encode
Calculates a cryptographic hash by using a specified algorithm. Use this helper when you need to select the hashing algorithm with named parameters.
Cryptographic hashes are one-way values and aren’t suitable for securely storing passwords or other sensitive data. For new implementations, use SHA-256 or SHA-512. Use MD5 and SHA-1 only for legacy compatibility.
Note
Availability
This helper is available in the Winter ’27 release of Marketing Cloud Next.
Syntax
1{{encode alg=ALGORITHM value=STRING_TO_ENCODE [charset=CHARSET]}}Parameters
| Parameter | Type | Description |
|---|---|---|
alg | String | Required. The hashing algorithm to use. Specify as a named parameter with one of these values: md5, sha1, sha256, or sha512. |
value | String | Required. The string to hash. Specify as a named parameter. |
charset | String | The character encoding to use. Specify as a named parameter with a value of UTF-8 or UTF-16. The default is UTF-8. |
Return Value
The function returns the hash as a lowercase hexadecimal string. The length of the string depends on the selected algorithm.
The function throws a DATA_ATTRIBUTES_ERROR if a required parameter is missing or if you specify an unsupported algorithm or character encoding.
Usage Examples
This example generates a SHA-256 hash.
1{{encode alg="sha256" value="Hello World"}}The function returns this SHA-256 hash:
1a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146eThis example generates a hash by using UTF-16 character encoding.
1{{encode alg="sha256" value="Hello World" charset="UTF-16"}}The function returns:
15908535fdaa4eb2d8f5b7b5e237cd0168298eed9d9083caf7d141b3121121157See Also
Let us know so we can improve!