Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jedisct1/js-base64-ct

Safe Base64 encoding/decoding in pure JavaScript.
https://github.com/jedisct1/js-base64-ct

base64 constant-time javascript typescript

Last synced: about 2 months ago
JSON representation

Safe Base64 encoding/decoding in pure JavaScript.

Awesome Lists containing this project

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

Available on NPM: [base64-ct](https://www.npmjs.com/package/base64-ct)

Usage:

- Traditional alphabet, padding:

```js
const codec = new Base64(true);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
```

- Traditional alphabet, no padding:

```js
const codec = new Base64(false);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
```

- URL-safe, no padding:

```js
const codec = new Base64UrlSafe(false);
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
```

- URL-safe, padding, ignoring spaces and `\n`:

```js
const codec = new Base64UrlSafe(true, " \n");
const b64 = codec.encode(data);
const data2 = codec.decode(b64);
```