Encoding / Decoding base64 Strings in the Terminal

01-22-2021

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

1
echo < string to interpret > | base64
1
echo testuser:testpass | base64

Decoding

Decoding a base64 string just requires us to use the --decode flag.

1
echo < string to interpret > | base64 --decode
1
echo dGVzdHVzZXI6dGVzdHBhc3MK | base64 --decode

Result: testuser:testpass