set_encode_base32

Encodes a string to Base32 format.

Syntaxset_encode_base32 $input_variable [padding];
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1-2

Description

The set_encode_base32 directive encodes a given string into Base32 format, which is particularly useful for data representation in environments where only ASCII characters are allowed. This directive operates by transforming the input based on a predefined alphabet and includes an option for padding the output with '=' characters. The Base32 encoding method is often used to encode binary data as a string to facilitate storage and transmission in text-based formats.

This directive can accept one to two parameters: the variable to be encoded and an optional padding flag. The padding, if enabled, ensures the encoded output meets the necessary length for certain applications that require a consistent block size. The encoded result is stored in a variable specified by the user, which can then be utilized elsewhere in the NGINX configuration or returned in responses to clients.

Config Example

location /encode {
    set $input_data "Hello, World!";
    set_encode_base32 $output_data;
    add_header Content-Type text/plain;
    return 200 $output_data;
}

Ensure that the input variable contains a valid string before applying this directive to avoid unexpected results.

Be cautious of the padding option, as incorrectly handling it could lead to decoding issues later on.

← Back to all directives