set_encode_base64
The `set_encode_base32` directive encodes a given variable value into Base32 format.
Description
The set_encode_base32 directive processes a string variable and encodes it into Base32 format, which is a way to encode binary data into an ASCII string. This is particularly useful for representing binary data in environments that are not binary-safe. The directive takes one or two arguments; the primary argument is the variable to be encoded, and the optional second argument specifies padding behavior, indicating whether to include padding characters in the encoded output. When a variable is encoded, the data is transformed using a Base32 encoding scheme, which replaces binary data with printable ASCII characters, thus enabling safe text representation.
For example, if you have a variable containing sensitive data, you can use set_encode_base32 to convert it into a more transmission-friendly format, avoiding issues with binary data handling in logs or HTTP headers. Additionally, this directive's context can be used in http, server, location, and within if blocks, making it versatile for various configurations. The processed output is then stored in another variable, allowing for further use in NGINX operations such as headers or response body modifications.
Config Example
location /example {
set $data "Hello World!";
set_encode_base32 $data;
add_header X-Encoded-Data $data;
}Ensure the input variable is defined; otherwise, the encoding may fail.
Be aware of output variable overwrites; the result is stored in the same variable if not redirected.