AMPscript SHA1 (Next)
Hash a value with AMPscript SHA1 in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including which character sets Next accepts.
Syntax
SHA1(stringToConvert[, charSet]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
stringToConvert |
string | number | date | Yes | The value to hash |
charSet |
string | No | Name of the character encoding applied before hashing; defaults to UTF-8. Next accepted UTF-16; ASCII and unknown names are rejected at save |
Example
%%=SHA1("Hash example 2026")=%%
Renders 93135d2253cdf62bb977c529a47739baaa649db4.
Return value
string — 40 lowercase hexadecimal characters with no separators.
There is no error token to test for: every accepted call returns a digest.
Behaviour
The digest is standard SHA-1. SHA1("abc") gives a9993e364706816aba3e25717850c26c9cd0d89d, and Length(SHA1("Hash probe 2026")) gives 40.
The empty string is hashed. SHA1("") gives da39a3ee5e6b4b0d3255bfef95601890afd80709, the digest of zero bytes.
UTF-8 bytes are hashed by default. SHA1("Grusß €ä") gives 57418a4484a6e50107c9c73d57333982344f4ebd.
UTF-16 changes the digest. SHA1("Grusß €ä", "UTF-16") gives 94b0370f99d4327e50edf287eca69e945f3741d7, and SHA1("Hash probe 2026", "UTF-16") gives 12ebd4a9b721eda440d263131f1e29fad920fede.
ASCII and unknown names are refused at save. An email containing SHA1("Grusß €ä", "ASCII") or SHA1("Hash probe 2026", "banana") cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
Wrong argument counts are refused at save. SHA1() and a call with three arguments are rejected the same way.
Show Next test script
<!-- Marketing Cloud Next test script for SHA1. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[a9993e364706816aba3e25717850c26c9cd0d89d] got=[%%=SHA1("abc")=%%]</p>
<p>c2 expect=[da39a3ee5e6b4b0d3255bfef95601890afd80709] got=[%%=SHA1("")=%%]</p>
<p>c3 expect=[20903bc0c930c22be005bfb1ede7db6722452ee7] got=[%%=SHA1("Hash probe 2026")=%%]</p>
<p>c4 expect=[40] got=[%%=Length(SHA1("Hash probe 2026"))=%%]</p>
<p>c5 expect=[57418a4484a6e50107c9c73d57333982344f4ebd] got=[%%=SHA1("Grusß €ä")=%%]</p>
<p>c6 expect=[12ebd4a9b721eda440d263131f1e29fad920fede] got=[%%=SHA1("Hash probe 2026","UTF-16")=%%]</p>
<p>c7 expect=[94b0370f99d4327e50edf287eca69e945f3741d7] got=[%%=SHA1("Grusß €ä","UTF-16")=%%]</p>
<p>c8 expect=[0af2f4853cc89dc1e1efe397ca334ce7a19d14da] got=[%%=SHA1("This is a string of text.")=%%]</p>
<p>c9 expect=[93135d2253cdf62bb977c529a47739baaa649db4] got=[%%=SHA1("Hash example 2026")=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the save is rejected (HTTP 400) -->
%%=SHA1("Grusß €ä","ASCII")=%%
<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=SHA1("Hash probe 2026","banana")=%%
<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=SHA1()=%%
<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=SHA1("Hash probe 2026","UTF-8","extra")=%%
Differs from official docs
- Available in Next. The official reference marks SHA1 as not available in Marketing Cloud Next. It saved and rendered correctly in a Next email (see the examples above). Details
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 68.0 |
Engagement accepts ASCII as the character set (SHA1("Grusß €ä", "ASCII") gives 601fc90e786918f662cece34acf5cdb0b1f8fade, the digest of Grus? ??); Next rejects an email with that call at save. Digests for UTF-8 and UTF-16 are identical on both. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- MD5
- SHA256
- SHA512 — the same signature, different digest lengths
- Official reference