Base64 decode to file

Useful if you’ve just received an email that says it has attachments but you can’t get them out (as I just did!). View the raw source of the email, copy the Base64 encoded text, drop in to a file, and run through this. The output will be the binary (or ascii) attachment.

perl -MMIME::Base64 -ne 'print decode_base64($_)' < file.txt > out

3 Responses to “Base64 decode to file”

  1. I was looking for how to do this, and then, after I read your post, I realized I had already learned a simpler way.
    On Linux, the coreutils package comes with a program called simply “base64″
    To use it in the same way you described, just do this:
    base64 -d file.txt > out
    A lot quicker to type, and easier to remember.

    Just thought you’d like to know!

  2. i would recommend base64 -d also

  3. base64 not decode June 25th, 2013 at 9:01 pm

    If you are decoding bad email attachments use “base64 -di file.txt > out” instead, to ignore some garbage(eg. carriage return) on mail dumps.

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight