Quicktip: Working with base64 in the shell

Recently I found myself looking on some base64 encoded values while debugging.
I had an assumption about inputs and wanted to tell if the string I was looking at was the correct base64 encoded representation of those inputs.
I needed a quick answer and I did not want to use one of the base64 encoders/decoders that are available online.
Turns out with Bash (or Cygwin, if you use Windows) you have everything you need for this simple task:

$ echo -n "param1:param2" | base64
$ echo -n "cGFyYW0xOnBhcmFtMg==" | base64 -d

Just be sure to add -n option for echo, otherwise a newline is added and encoded!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.