one melo a day

moon indicating dark mode
sun indicating light mode

Quicktip: Working with base64 in the shell

July 15, 2016

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: [code language=“bash”] $ echo -n “param1:param2” | base64 cGFyYW0xOnBhcmFtMg== $ echo -n “cGFyYW0xOnBhcmFtMg==” | base64 -d param1:param2 [/code] Just be sure to add -n option for echo, otherwise a newline is added and encoded!