Base64 decode on the command line

There are several options to decode a base64-encoded file on the command line, or vice-versa, encode some text to base64. base64 is probably the easiest command to use and easiest to remember, however, it might not be available on every system. In that case the other two options are viable alternatives.

base64

(install with sudo apt-get install coreutils)

Encode/Decode: base64 [-d / -e] infile outfile

Use -d for decode.
Use -e for encode.
Both infile and output can be ‘-‘, meaning that the input will be read from stdin, and/or the output will be written to stdout, respectively.

perl one-liner (found here)

(install with sudo apt-get install perl)

Encode: perl -MMIME::Base64 -ne 'print encode_base64($_)' < infile > outfile
Decode: perl -MMIME::Base64 -ne 'print decode_base64($_)' < infile > outfile

openssl

(install with sudo apt-get install openssl)

Encode: openssl enc -base64 -in infile -out outfile
Decode: openssl enc -d -base64 -in infile -out outfile

Advertisements

One Response to Base64 decode on the command line

  1. base64 -d is the right command 🙂

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: