---
schema_version: "1"
id: 600dcb27971ea3354704e0bd3473368205e06f2c2aa614567f1f75f41e6400c0
title: SHA256()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/encryption/mc-ampscript-reference-encryption-sha256.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-encryption/mc-ampscript-reference-encryption-sha256.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a1a4f2e07ee15a7e85111356bae9f2c60a8e11b5ac03aadab96547fc263bdd9f
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# SHA256()

Converts a string to a 256-bit hexadecimal SHA-2 hash.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>✅ Yes</td>
  </tr>
</table>

## Syntax

```
SHA256(stringToConvert, charSet)
```

The `SHA256()` function has two parameters:

- `stringToConvert` (string): Required. The string to encode.
- `charSet` (string): The character set to use for encoding. Accepted values are `UTF-8` and `UTF-16`. The default value is `UTF-8`.

## Usage

To use this function, pass it a string.

```
%%=SHA256("This is a string of text.")=%%
```

The function outputs a SHA-2 hash of the provided string: `99d1f7b534824f35dffa18c3b728ecb00c4585ba9d7c9b26205424f8f28eff8e`

You can also generate the hash using UTF-16 encoding, as in this example.

```
%%=SHA256("This is a string of text.", "UTF-16")=%%
```

The function outputs a SHA-2 hash that uses UTF-16 encoding: `84b87f1ae08610f97a0bb6c228dd2289a54203c23ee2af17d617a1c1b4a0ab1a`
