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.
This helper is available in the Winter ’27 release of Marketing Cloud Next.
| 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. |
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.
This example generates a SHA-256 hash.
The function returns this SHA-256 hash:
This example generates a hash by using UTF-16 character encoding.
The function returns: