AMPscript MD5 (Next)
Hash a value with AMPscript MD5 in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including which character sets Next accepts and how dates are hashed.
Syntax
MD5(stringToConvert[, charSet]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
stringToConvert |
string | number | date | Yes | The value to hash; a number or date is hashed as text |
charSet |
string | No | Name of the character encoding applied before hashing; defaults to UTF-8. Next accepts only UTF-8 and UTF-16, in any letter case; other names are rejected at save |
Example
%%=MD5("abc")=%%
Renders 900150983cd24fb0d6963f7d28e17f72.
Return value
string — 32 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 MD5. MD5("abc") gives 900150983cd24fb0d6963f7d28e17f72, and Length(MD5("SFMC-Probe-2026")) gives 32.
The empty string is hashed. MD5("") gives d41d8cd98f00b204e9800998ecf8427e, the digest of zero bytes.
UTF-8 bytes are hashed by default. MD5("Grusß €ä") gives 45e83c6ea8202aae452acf5f61f0d660, and naming "UTF-8" (or "utf-8") gives the same digest as leaving it out.
UTF-16 changes the digest. MD5("Grusß €ä", "UTF-16") gives 75300cf3b34da08a0cfd6958b26e1bae; the lowercase spelling "utf-16" behaves the same.
Numbers are hashed as their digits. MD5(12345) gives 827ccb0eea8a706c4c34a16891f84e7b and MD5(2026) gives c92a10324374fac681719d63979d00fe.
Dates are hashed in M/d/yyyy h:mm:ss AM form. MD5(StringToDate("2026-03-04T09:05:07")) gives f78066a00e33be48d6f2f9914f6b6066, exactly the digest of the text 3/4/2026 9:05:07 AM. This holds even though Next writes the same kind of date as 2026-11-22T22:41:45 when you output it with Concat, so hashing a date and hashing its printed form give different digests.
Only two character sets are accepted. An email that passes UTF-16BE, UTF-32, ASCII, ISO-8859-1, the dashless UTF8, banana, an empty string, a number or a boolean as the second argument cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
Wrong argument counts are refused at save. MD5() and a call with three arguments are rejected the same way.
Show Next test script
<!-- Marketing Cloud Next test script for MD5. 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=[900150983cd24fb0d6963f7d28e17f72] got=[%%=MD5("abc")=%%]</p>
<p>c2 expect=[672477678e312bd05531722d736f5f35] got=[%%=MD5("SFMC-Probe-2026")=%%]</p>
<p>c3 expect=[d41d8cd98f00b204e9800998ecf8427e] got=[%%=MD5("")=%%]</p>
<p>c4 expect=[827ccb0eea8a706c4c34a16891f84e7b] got=[%%=MD5(12345)=%%]</p>
<p>c5 expect=[32] got=[%%=Length(MD5("SFMC-Probe-2026"))=%%]</p>
<p>c6 expect=[479e7b3b0e52eee6bec133fe72cd42c3] got=[%%=MD5(Concat("Zurich", Char(228), "1"))=%%]</p>
<p>c7 expect=[672477678e312bd05531722d736f5f35] got=[%%=MD5("SFMC-Probe-2026","UTF-8")=%%]</p>
<p>c8 expect=[0871c872a59e5fc3d4fd72799f8f7138] got=[%%=MD5("SFMC-Probe-2026","UTF-16")=%%]</p>
<p>c9 expect=[9d5390fabd29cb49bb3b2a85e7725469] got=[%%=MD5(Concat("Zurich", Char(228), "1"),"UTF-16")=%%]</p>
<p>c10 expect=[672477678e312bd05531722d736f5f35] got=[%%=MD5("SFMC-Probe-2026","utf-8")=%%]</p>
<p>c11 expect=[0871c872a59e5fc3d4fd72799f8f7138] got=[%%=MD5("SFMC-Probe-2026","utf-16")=%%]</p>
<p>c12 expect=[45e83c6ea8202aae452acf5f61f0d660] got=[%%=MD5("Grusß €ä")=%%]</p>
<p>c13 expect=[75300cf3b34da08a0cfd6958b26e1bae] got=[%%=MD5("Grusß €ä","UTF-16")=%%]</p>
<p>c14 expect=[c92a10324374fac681719d63979d00fe] got=[%%=MD5(2026)=%%]</p>
<p>c15 expect=[f78066a00e33be48d6f2f9914f6b6066] got=[%%=MD5(StringToDate("2026-03-04T09:05:07"))=%%]</p>
<p>c16 expect=[f78066a00e33be48d6f2f9914f6b6066] got=[%%=MD5("3/4/2026 9:05:07 AM")=%%]</p>
<p>c17 expect=[2026-11-22T22:41:45|56a86d9ce6b533bf2372355939f52726] got=[%%[SET @md5now = Now()]%%%%=Concat(@md5now,"|",MD5(@md5now))=%%]</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) -->
%%=MD5("SFMC-Probe-2026","UTF-16BE")=%%
<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","UTF-32")=%%
<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","ASCII")=%%
<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=MD5(Concat("Zurich", Char(228), "1"),"ASCII")=%%
<!-- email 5: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","ISO-8859-1")=%%
<!-- email 6: expect that the save is rejected (HTTP 400) -->
%%=MD5(Concat("Zurich", Char(228), "1"),"ISO-8859-1")=%%
<!-- email 7: expect that the save is rejected (HTTP 400) -->
%%=MD5("Grusß €ä","ASCII")=%%
<!-- email 8: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","NOT-A-CHARSET")=%%
<!-- email 9: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","")=%%
<!-- email 10: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","banana")=%%
<!-- email 11: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","UTF8")=%%
<!-- email 12: expect that the save is rejected (HTTP 400) -->
%%=MD5()=%%
<!-- email 13: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026","UTF-8","UTF-8")=%%
<!-- email 14: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026",1)=%%
<!-- email 15: expect that the save is rejected (HTTP 400) -->
%%=MD5("SFMC-Probe-2026",true)=%%
Differs from official docs
- Available in Next. The official reference marks MD5 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 also accepts ASCII as the character set (MD5("Grusß €ä", "ASCII") gives 1a7a47e1752ce663f442793ac4b38476, the digest of Grus? ??) and further names such as UTF-16BE, UTF-32 and ISO-8859-1; Next rejects an email with any of them at save. Digests for UTF-8, UTF-16, numbers and dates are identical on both. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- SHA1
- SHA256
- SHA512 — the same signature, longer digests
- Official reference