Skip to main content
Deno 2 is finally here 🎉️
Learn more

RSA for WebAssembly

WebAssembly port of RustCrypto’s RSA, a Rust implementation of RSA encryption and signatures.

Install (Node)

npm i @hazae41/paimon

Usage

import * as Paimon from "@hazae41/paimon";
import { PaddingScheme, RsaPrivateKey } from "@hazae41/paimon";

// Wait for WASM to load
Paimon.initSyncBundledOnce()

// Generate an identity
const keypair = new RsaPrivateKey(1024)
const identity = keypair.to_public_key()

// Define bytes to sign and padding to use
const bytes = new TextEncoder().encode("hello world")
const padding = PaddingScheme.new_pkcs1v15_sign_raw()

// Sign and verify
const proof = keypair.sign(padding, bytes)
const verified = identity.verify(padding, bytes, proof)

Building

https://deno.land

  • Install binaryen (for wasm-opt) and add it your PATH

https://github.com/WebAssembly/binaryen/releases

cargo install wasm-pack
  • Install dependencies
npm install
  • Build wasm and module
npm run build