Base64 encoding/decoding

How to encode and decode a message in base64  through your unix terminal:

$ echo 'This is a base64 encoded sentence!' | base64

To decode just add the -d parameter (or capital -D if you’re on MacOS).

$ echo 'VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHNlbnRlbmNlIQo=' | base64 -d
This is a base64 encoded sentence!


If you want to encode/decode a text file:

openssl base64 -in 'input.txt' -out 'encodedfile.txt'
openssl base64 -d -in 'encodedfile.txt' -out 'input.txt'

This is the basic manipulation. Try to encode your messages several times, adding unnecessary characters between two pass.

And of course, for an intensive use, better put it in your .bashrc:

encode () { 
  echo "$1" | base64 ; echo 
decode () {
  echo "$1" | base64 -d ; echo

In the next post we’ll have a look at a real GPG message encryption.


Comments are closed.

Blog at

Up ↑