Base32
Encode and decode RFC 4648 Base32 — the case-insensitive, digit-light alphabet used for TOTP / 2FA secrets, DNSSEC NSEC3 hashes, and human-transcribable identifiers. Both RFC 4648 variants are supported: the standard alphabet (variant: "rfc4648", default) and the extended-hex alphabet (variant: "rfc4648-hex", which sorts in the same order as the underlying bytes).
encode pads to an 8-character boundary with = by default (pass padding: false for the bare form TOTP key URIs use). decode is strict by default — it rejects any character outside the alphabet — but loose: true accepts the real-world shapes humans produce: lower-case input, embedded spaces and dashes, and missing padding.
b.base32.encode(input, opts?) #
{
variant: "rfc4648" | "rfc4648-hex", // default: "rfc4648"
padding: boolean, // default: true
}
Encode a Buffer (or Uint8Array) to an RFC 4648 Base32 string. Output is padded to an 8-character boundary with = unless padding: false. The empty input encodes to the empty string.
b.base32.encode(Buffer.from("foobar"));
// → "MFRGGZDFMZTWQ===="
b.base32.decode(str, opts?) #
{
variant: "rfc4648" | "rfc4648-hex", // default: "rfc4648"
loose: boolean, // default: false
}
Decode an RFC 4648 Base32 string to a Buffer. Strict by default: any character outside the variant's alphabet (other than trailing = padding) throws Base32Error. With loose: true the decoder up-cases the input and ignores embedded spaces and dashes (and missing padding) — the shapes TOTP keys and hand-typed codes take.
b.base32.decode("MFRGGZDFMZTWQ====").toString();
// → "foobar"
Last updated 2026-08-08T16:39:49.652Z by seeder.