AES-CTR for WebAssembly
WebAssembly port of RustCrypto’s AES + CTR, Rust implementations of AES encryption with CTR mode.
npm i @hazae41/zepar
Usage
import * as Zepar from "@hazae41/zepar";
import { Aes128Ctr128BEKey } from "@hazae41/zepar";
import { randomBytes } from "crypto";
// Wait for WASM to load
Zepar.initSyncBundledOnce()
// Random key
const key = randomBytes(16)
// Empty IV
const iv = new Uint8Array(16)
// Build a cipher from key and IV
const cipher = new Aes128Ctr128BEKey(key, iv)
// Byte arrays to encrypt
const hello = new TextEncoder().encode("Hello World")
const hello2 = new TextEncoder().encode("Hello World")
// Encrypt with counter = 0
cipher.apply_keystream(hello)
// Encrypt with counter = 1
cipher.apply_keystream(hello2)
// hello !== hello2
console.log(hello, hello2)
Building
- Install Deno
- Install binaryen (for wasm-opt) and add it your PATH
https://github.com/WebAssembly/binaryen/releases
- Install wasm-pack
cargo install wasm-pack
- Install dependencies
npm install
- Build wasm and module
npm run build