base64_encode
Encodes a string to Base64 format. Useful for encoding data for APIs, creating basic authentication headers, or encoding binary data for transmission.
{% assign encoded = "Hello, World!" | base64_encode %}
{% log encoded %}Output:
SGVsbG8sIFdvcmxkIQ==Syntax
{{ string | base64_encode }}string
The text to encode
Examples
Create Basic Authentication header:
{% assign credentials = "username:password" | base64_encode %}
{% assign auth_header = "Basic " | append: credentials %}
{% json http_options %}
{
"url": "https://api.example.com/data",
"method": "GET",
"headers": {
"Authorization": "{{ auth_header }}"
}
}
{% endjson %}
{% http options: http_options as response %}Encode API credentials:
Encode JSON payload for URL parameter:
Encode data for webhook signature:
Create encoded return URL:
Encode file content reference:
Encode special characters for safe transmission:
Output:
Encode Unicode/international characters:
Output:
Common Use Cases
HTTP Basic Auth
`"user:pass"
API tokens
`"api_key:secret"
URL-safe data
Encode JSON for query strings
Webhook signatures
Encode payload before signing
Data obfuscation
Hide readable values (not encryption!)
Notes
Supports UTF-8 encoding (handles international characters correctly)
Output is standard Base64 (uses
+,/, and=padding)For URL-safe Base64, you may need to replace characters:
| replace: "+", "-" | replace: "/", "_"Base64 encoding increases size by approximately 33%
This is encoding, not encryption - data can be easily decoded
See also:
base64_decodefor decoding Base64 strings
Last updated