Adjustable base64 encoding and decoding in Javascript.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
base64.js
index.html
test.html

README.md

See the demo.

This script encodes to and decodes from base64. It allows you to specify a few parameters:

  • The non-alphanumeric characters.
  • The padding character, or lack thereof.
  • 8-bit or 16-bit string input.

Your standard base64 uses + and / as the non-alphanumeric characters, and = as the padding character. Now say you want base64url. No problem. Just use the following settings:

base64.settings.char62 = "-";
base64.settings.char63 = "_";
base64.settings.pad = null;

In terms of input, 8 bits is the standard. However, with only 8 bits, you can't encode Chinese characters, for example. 16 bits gives lengthier output, but allows you to preserve full Unicode fidelity as Javascript strings themselves are just arrays of 16-bit values.

test.html contains a few tests.