Base64Encode Function

The Base64Encode function converts a string value to Base64 which is an encoding scheme used to represent binary data in an ASCII format. This is useful when binary data needs to be sent over media that are usually designed to handle textual data. Similar functions are Base64Decode and StringToHex.

Syntax:



Base64Encode(1)
1 = String value (can be a variable)
2 = Character set for encoding. Defaults to UTF-8 but can use UTF-16

Example:



%%[
set @string = “Base64 encoding of a string”
]%%
%%=Base64Encode(@string)=%%

Output:

QmFzZTY0IGVuY29kaW5nIG9mIGEgc3RyaW5n

Explanation:

In the AMPscript above, first we are declaring the variables using the var function. Then defining the @string variable as “Base64 encoding of a string”

The output of that value is shown as binary-to-text encoding that represents binary data in a sequence of 8-bit bytes. If you were to use the Base64Decode function on the output above, it would give you the value of the string “Base64 encoding of a string”

Leave a Reply

Your email address will not be published. Required fields are marked *