base64-ct
v1.0.0
Published
Safe, constant-time Base64 encoding and decoding in pure JavaScript, with support for common Base64 variants.
Downloads
5
Maintainers
Readme
Safe Base64 codecs for JavaScript
A pure JavaScript port of the libsodium base64 codecs.
Features:
- Supports traditional and URL-safe variants, with or without padding
- Rejects non-canonical padding
- Constant-time (best-effort), suitable for encoding/decoding secrets
- Characters can be ignored by the decoder
Usage:
- Traditional alphabet, padding:
const codec = new Base64(true);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
- Traditional alphabet, no padding:
const codec = new Base64(false);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
- URL-safe, no padding:
const codec = new Base64UrlSafe(false);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
- URL-safe, padding, ignoring spaces and
\n
:
const codec = new Base64UrlSafe(true, " \n");
const b64 = codec.encode(data);
const data2 = codec.decode(b64);