# 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](/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-md5.md)
- [SHA1](/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha1.md)
- [SHA256](/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha256.md)
- [SHA512](/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-encryption-references/mcn-handlebars-reference-encryption-sha512.md)
