BASE64 encoding CONTENTS

BASE64 encoding

BASE64 encoding performs any binary data as text (using only printable characters). Such text representation allows to pass binary data via a channel or save to a storage intended for text only, for example: e-mail software uses BASE64 encoding to hold attached files.

J-Painter uses BASE64 encoding to return image data to JavaScript, post them to the server using standrad post request, or accept an image file via the canvas parameter "image".

Encoding example:

This image is retrieved from a binary file. BASE64 encoded version of this file looks as follows:

iVBORw0KGgoAAAANSUhEUgAAACAAAAATBAMAAAADuhLEAAAABGdBTUEAALGP
C/xhBQAAAAFzUkdCAdnJLH8AAAAPUExURYSEhP///wAAAP//AP8AACykMFsA
AABsSURBVHjahdDBDcMwDENRWhsw9AJRuwCBLuAi+8+UQ+rGTg75NwkPECBg
LlDmAuBUoCyZfapbm4Tr1gJlybVvPt/XKMz6boHyX4iWBmGKdBf5i6cwSVpX
4fGKnoRpqQsdV+1TmLYkBW4Pyks7gc8WIpISYokAAAAASUVORK5CYII=

You can find the encoding technique here: http://www.ietf.org/rfc/rfc1521.txt, but most likely you needn't know them because many server-side scripting languages support functions for BASE64 encoding/decoding.

How to decode BASE64 encoded data in different scripting languages.

PHP

PHP has built in functions for BASE64 encoding and decoding:

base64_decode();
base64_encode();

ASP.NET

Use the function:
System.Convert.FromBase64String(baseString);

ASP

ASP has not built in functions for BASE64 decoding, but you can find a nice VBScript implementation of this function here http://www.pstruh.cz/tips/detpg_Base64.htm

Perl

For BASE64 decoding you may use the function

MIME::Base64::decode($encoded)

Java

There are a lot of BASE64 encoding/decoding implementations in Java. For example, you may use my own implementation Base64.java. This file is located in the JSP example directory.