Skip to content

Getting Started

Installation

Add the crate with the features you need:

sh
# Just hashing
cargo add wasm_web_crypto --features digest

# JWT signing
cargo add wasm_web_crypto --features sign,key

# Everything
cargo add wasm_web_crypto --features full

Available features

FeatureAPI
randomCrypto::get_random_values, Crypto::random_uuid
digestSubtleCrypto::digest
signSubtleCrypto::sign, SubtleCrypto::verify
encryptSubtleCrypto::encrypt, SubtleCrypto::decrypt
keySubtleCrypto::import_key, export_key, generate_key
deriveSubtleCrypto::derive_key, derive_bits
wrapSubtleCrypto::wrap_key, unwrap_key
fullAll of the above

Quick example

rust
use wasm_web_crypto::{Hash, SubtleCrypto};

let subtle = SubtleCrypto::new()?;
let hash = subtle.digest(Hash::Sha256, b"hello").await?;
println!("{}", hash.to_hex());
// 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Non-wasm targets

On non-wasm targets, the crate compiles but all methods return Err(WebCryptoError::NonWasmBuild). This means the crate can exist in your dependency tree without breaking native builds or cargo check.