Linux Base64 encoding and decoding string value

A silhouette of a person sitting in front of a computer screen.

Base64 encoding is a method of encoding binary data into an ASCII (text-based) format. In Linux and other computing environments, Base64 encoding is commonly used to represent binary data in a human-readable form. This encoding is used for different purposes. It encodes binary files for transmission over protocols that use text. It can also embed binary data in text-based formats like JSON or XML.

Base64 encoding converts groups of 3 bytes (24 bits) from binary data into 4 characters from a set of 64 predefined characters, which usually include uppercase letters, lowercase letters, digits, and a few special characters. When the length of binary data is not divisible by 3, padding characters, often represented by the symbol ‘=’, are added to the encoded output. This ensures that the total number of characters is a multiple of 4.

From the Linux command line interface, execute the below commands to encode or decode string values.

Encoding

echo -n 'tekspace' | base64

Output:

dGVrc3BhY2U=

Decoding

echo -n dGVrc3BhY2U= | base64 -d

Output:

tekspace

Leave a Comment

Scroll to Top