Skip to main content
The base64_encode_tostring function encodes a string into Base64 format. Use this function when you need to encode data for transmission or storage in systems that only support text-based formats, such as APIs, configuration files, or log analysis pipelines.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you might not have a built-in Base64 encoding function and would typically rely on external scripts or commands. In APL, base64_encode_tostring provides native Base64 encoding directly in your queries.
| eval encoded=base64encode(field_name)
In ANSI SQL, Base64 encoding typically requires database-specific functions like TO_BASE64() in MySQL or custom functions. APL provides base64_encode_tostring as a standard function.
SELECT TO_BASE64(field_name) AS encoded FROM logs;

Usage

Syntax

base64_encode_tostring(value)

Parameters

NameTypeRequiredDescription
valuestringYesThe input string to be encoded as Base64.

Returns

Returns the input string encoded as a Base64 string.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Encode HTTP content types for secure transmission or storage in Base64 format.Query
['sample-http-logs']
| extend encoded_content_type = base64_encode_tostring(content_type)
| project _time, content_type, encoded_content_type
| limit 10
Run in PlaygroundOutput
_timecontent_typeencoded_content_type
2024-11-06T10:00:00Zapplication/jsonYXBwbGljYXRpb24vanNvbg==
2024-11-06T10:01:00Ztext/htmldGV4dC9odG1s
This query encodes the content type of each HTTP request into Base64 format, which is useful when you need to pass content types through systems that have character restrictions.
  • base64_decode_tostring: Decodes a Base64-encoded string back to its original UTF-8 format. Use this when you need to reverse the encoding operation.
  • base64_encode_fromarray: Encodes an array of bytes into a Base64 string. Use this when working with binary data rather than text strings.
  • base64_decode_toarray: Decodes a Base64 string into an array of bytes. Use this when you need to work with the raw binary representation.
  • url_encode: Encodes a URL string for safe transmission. Use this when working with URLs rather than general text encoding.