Simple Base64 Encode & Decode on Mac OSX / Linux with OpenSSL

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.


Author: drewsymo


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s