Base64 is an encoding and decoding scheme commonly used to convert binary data into a printable ASCII text format and back. This tutorial demonstrates how to perform Base64 encoding and decoding using OpenSSL.
Commands have been tested on Ubuntu.
Encoding string
The openssl base64
command allows you to perform Base64 encoding and decoding. You can encode a string as shown below:
echo "Hello world" | openssl base64
Decoding string
To decode Base64, use the -d
option:
echo "SGVsbG8gd29ybGQK" | openssl base64 -d
Encoding file
Create a text file for testing:
echo "Hello world" > data.txt
Encode the content of a text file and display the result in the terminal:
openssl base64 -in data.txt
Encode the content of a text file and save the result to a different file:
openssl base64 -in data.txt -out out.txt
Decoding file
Create a text file containing Base64 encoded data:
echo "SGVsbG8gd29ybGQK" > encoded_data.txt
Decode the content of a text file and display the result in the terminal:
openssl base64 -d -in encoded_data.txt
Decode the content of a text file and save the result to a different file:
openssl base64 -d -in encoded_data.txt -out out.txt
Leave a Comment
Cancel reply