---
schema_version: "1"
id: 06cd61e40647b2e62a56a54cbe05167464c2e20e4943dcf66079fc041db24c06
title: "Handlebars Helper Function: encode"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/encryption/mcn-handlebars-reference-encryption-encode.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-encode.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 569bf42fd630389d16089d18e46d02861432703995e937439d8960ee51ea6063
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# 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.

**note:** 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.

## Availability

This helper is available in the Winter ’27 release of Marketing Cloud Next.

## Syntax

```handlebars
{{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.

```handlebars
{{encode alg="sha256" value="Hello World"}}
```

The function returns this SHA-256 hash:

```text
a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
```

This example generates a hash by using UTF-16 character encoding.

```handlebars
{{encode alg="sha256" value="Hello World" charset="UTF-16"}}
```

The function returns:

```text
5908535fdaa4eb2d8f5b7b5e237cd0168298eed9d9083caf7d141b3121121157
```

## See Also

- [MD5](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-md5.md)
- [SHA1](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha1.md)
- [SHA256](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha256.md)
- [SHA512](https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha512.md)
