Looking for a fast and convenient way to Base64 encode / decode a given string using your Mac or Linux machine? You can do it using the pre-installed OpenSSL package.
Base64 Encode using OpenSSL on Mac / Linux
echo 'mystring' | openssl base64
The above command will Base64 encode any contents within the quotes, i.e. msystring, and display the encoded contents on a new line.
If you wanted to Base64 encode multiple lines, you can issue something similar to:
echo 'my first string' | openssl base64 && echo 'my second string' | openssl base64
Using the OpenSSL package, you can also Base64 encode a specified file, as seen below:
openssl base64 -in '/Desktop/tobeencoded.txt' -out '/Desktop/encodedfile.txt'
Base64 Decode using OpenSSL on Mac / Linux
It’s just as easy to decode a Base64 encoded file, simply specify the ‘-d’ flag, as seen below:
echo 'bXlzdHJpbmcK' | openssl base64 -d
The same applies for a specified file:
openssl base64 -d -in '/Desktop/tobeencoded.txt' -out '/Desktop/encodedfile.txt'
There you have it. Base64 monster.
