Base64 is an encoding and decoding scheme that often used to convert binary data to an printable ASCII text format, and vice versa. This tutorial shows how to perform Base64 encoding and decoding in Linux.
Encoding string
The base64
command can be used to perform Base64 encoding and decoding. String can be encoded as follows:
echo 'Hello world' | base64
Decoding string
For Base64 decoding use --decode
option.
echo 'SGVsbG8gd29ybGQK' | base64 --decode
Encoding file
Create a text file for testing:
echo 'Hello world' > data.txt
Encode content of a text file and print result in the terminal:
base64 data.txt
Encode content of a text file and save result in another file:
base64 data.txt > out.txt
Decoding file
Create a text file that contains Base64 encoded data:
echo 'SGVsbG8gd29ybGQK' > encoded_data.txt
Decode content of a text file and print result in the terminal:
base64 --decode encoded_data.txt
Decode content of a text file and save result in another file:
base64 --decode encoded_data.txt > out.txt
Leave a Comment
Cancel reply