Encoding / Decoding base64 Strings in the Terminal
Sometimes you need to deal with base64 strings, here are a couple commands that make it easy to encode/decode those strings using the terminal
Sometimes you need to deal with base64 strings, here are a couple commands that make it easy to encode/decode those strings using the terminal. I deal with various types of authentication strings a lot, which are often base64 encoded, and often need to quickly test and verify the base64 values Iโm using.
In your terminal you have access to the base64 program from the coreutils package installed on your machine by default. Using a simple echo statement we can encode/decode a base64 string. Hereโs an example:
Encoding
echo -n < string to interpret > | base64
echo -n testuser:testpass | base64
** Note: adding the -n flag to the echo statement prevents echo from inserting a new line statement by default, with possible unintended consequences (Thanks Tomasz ๐)
Decoding
Decoding a base64 string just requires us to use the --decode flag.
echo -n < string to interpret > | base64 --decode
echo -n dGVzdHVzZXI6dGVzdHBhc3MK | base64 --decode
Result: testuser:testpass
Dealing with something harder than a blog post can fix?
Book a 30-minute call โ