Home

Base64 Decoder

What is it?

b64dec Screenshot

A Base64 Decoder is a program that translates base64 encoded data back to its natural form. Base64 is an encryption algorithm often used for transmitting attachments in emails. I wrote this tiny tool because my email client doesn't support attachments -- it displays attached files as base64 encoded data in the message body. So I decided to write a decoder that allows me to extract the attachments out of the messages and to save it as files. It's a pretty simple and small program, but -- without it, I couldn't extract my attachments :)

B64Dec is not capable of parsing MIME headers. Instead of this, you have to manually copy-and-paste the base64 data out of the message body into the decoder.

Under Windows XP, B64Dec runs optimal. Under Windows 95/98, B64Dec cannot open files greater than 64 KB. This is due to limitations of the operating system (the Windows 95/98 multiline edit component is restricted to 64 KB).


Using parameters

You can use B64Dec from the command line by specifying the source and destination files. The syntax is as follows:

b64dec *C | "source-file" ["destination-file"]

For example:

C:\>b64dec *C

With this syntax, B64Dec expects the base64 encoded string in the clipboard. It will decode and save it back to the clipboard. The return value contains either a negative error code or the size of the decoded string.

C:\>b64dec encoded.txt dest.txt

This decodes "encoded.txt" to "dest.txt". The program window will not show up.

You can omit the "destination-file" parameter. In this case, B64Dec will generate a destination file name based on the source file name. It consists of a random number, followed by the source file name; that means that the command "b64dec encoded.txt" could generate a file named "2783-encoded.txt".

If used by command line, B64Dec returns an exit code. If the exit code is positive, it indicates the size of the decoded data (in bytes). If the exit code is negative, it is an error code. The following error codes exist:

CodeMeaning
-1illegal characters in input data
-2not enough memory
-3could not read from source file
-4could not write to destination file

The following DOS-style batch code could be used to call the decoder from the command line:

@echo off

b64dec %1 %2
if errorlevel 0 exit /B
if errorlevel -1 goto illegal
if errorlevel -2 goto memory
if errorlevel -3 goto source
if errorlevel -4 goto dest
exit /B

:illegal
echo illegal characters in input data
exit /B

:memory
echo not enough memory
exit /B

:source
echo could not read from source file
exit /B

:dest
echo could not write to destination file
exit /B


Download

B64Dec is freeware. You may distribute it freely, but only in the original and unchanged b64dec.zip file and NOT ON YOUR OWN WEBSITE. FREEWARE DOES NOT MEAN PUBLIC DOMAIN OR OPEN SOURCE. I hold all rights.

Feedback is always appreciated, especially if you encounter any bugs.

False positive backdoor alarm: As was pointed out to me recently (25 Sep 2009), two scanners report the B64Dec executable to be infected by Backdoor.Win32.JustJoke, a (harmless) malware. This is a false positive, meaning the file is not infected. (The scan results are available here at the website of the online scanner Jotti.)


Version history


last modified: 25 Sep 2009