Home > Text Processing & Search > base64

base64: Data Encoding/Decoding

The base64 command is used to encode binary data into an ASCII string format, or to decode an encoded string back into binary data. It is commonly used for safely transmitting binary data in email attachments or over the web.

Overview

base64 is an encoding method that represents data in base-64. This method converts every byte into a printable ASCII character, allowing binary data to be processed without corruption in text-based systems. It primarily processes data through standard input/output and also supports file input/output.

Key Features

  • Encode binary data into ASCII text
  • Decode encoded text back into binary data
  • Supports standard input/output and file processing
  • Enables data transmission without corruption

Key Options

The main options for the base64 command control the encoding/decoding method, output format, and more.

Basic Operations

Other Options

Generated command:

Try combining the commands.

Description:

`base64` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various usage examples of the base64 command.

Encoding a String

echo -n 'Hello, World!' | base64

Encodes a string to base64 using the echo command.

Decoding an Encoded String

echo -n 'SGVsbG8sIFdvcmxkIQ==' | base64 -d

Decodes a previously encoded string using the base64 -d option.

Encoding a File

echo 'This is a test file.' > test.txt
base64 test.txt > test.txt.base64

Encodes the content of a file to base64 and saves it to a new file. (Example: Create test.txt and then run)

Decoding an Encoded File

base64 -d test.txt.base64 > test_decoded.txt

Decodes an encoded file to restore the original file.

Encoding Without Line Breaks

echo -n 'Long string without line breaks for encoding' | base64 -w 0

Uses the -w 0 option to prevent line breaks in the output.

Encoding/Decoding with Pipes

cat /etc/hostname | base64 | base64 -d

Chains encoding and decoding operations using pipes for command output.

Tips & Precautions

Useful tips and precautions when using base64.

Key Tips

  • base64 is not an encryption tool. It converts data into a transmittable format, rather than hiding it. For sensitive data, use encryption tools.
  • When encoding binary files to base64, the output file size increases by approximately 33% compared to the original file. This is because 3 bytes of binary data are represented by 4 ASCII characters.
  • If you need to process a base64 string containing invalid characters during decoding, you can use the `--ignore-garbage` option to ignore errors and decode only the valid parts. However, this may lead to data loss, so use with caution.
  • When using base64 encoded data in a web environment, URL-safe base64 encoding might be necessary. The `base64` command follows standard base64, so if URL-safe encoding is required, an additional conversion step will be needed.

Same category commands