Base64 is a great way to pass data back and forth between servers and clients. However, most of the Base64 Javascript implementations available are huge and slow – and often don’t work as advertised. The following snippet is a modified Base64 version from the team at webtoolkit.info.

What is Base64? The term Base64 refers to a specific MIME content transfer encoding. It is also used as a generic term for any similar encoding scheme that encodes binary data by treating it numerically and translating it into a base 64 representation. The particular choice of base is due to the history of character set encoding: one can choose a set of 64 characters that is both part of the subset common to most encodings, and also printable. This combination leaves the data unlikely to be modified in transit through systems, such as email, which were traditionally not 8-bit clean.

The object

Using it

var mystring = "This is my string baby!";
var encodedString = Base64.encode(mystring);
var decodedString = Base64.decode(encodedString);
document.write("The string has been encoded and now decoded - the result is: " + decodedString);