encode/decode,

base64 encode and decode from the CLI

Jan 30, 2022 · 1 min read · Post a comment

Base64 encoding and decoding has many use cases, but it’s important to understand that it’s different from encryption and decryption. While base64 encoding focuses on data usability, so it can be properly consumed, encryption focuses on data confidentiality. Instead of using online base64 encoders / decoders for your data, you could do the same from the CLI.

Prerequisites

  • Base64

base64 encode

Step 1. Open Terminal and run the following command:

echo -n "devcoops.com" | base64 

Expected output:

ZGV2Y29vcHMuY29t

Step 2. Encode a text file. For instance:

base64 test.txt > output_encoded_test.txt

base64 decode

Step 1. Open Terminal and run the following command:

echo -n "ZGV2Y29vcHMuY29t" | base64 --decode

Expected output:

devcoops.com

Step 2. Decode a text file.

base64 --decode output_encoded_test.txt

Conclusion

It’s as easy and simple as it gets. On a side note, openssl base64 -in <in_file> -out <out_file> is another way you could try to encode and decode data. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.