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 fullAvailable features
| Feature | API |
|---|---|
random | Crypto::get_random_values, Crypto::random_uuid |
digest | SubtleCrypto::digest |
sign | SubtleCrypto::sign, SubtleCrypto::verify |
encrypt | SubtleCrypto::encrypt, SubtleCrypto::decrypt |
key | SubtleCrypto::import_key, export_key, generate_key |
derive | SubtleCrypto::derive_key, derive_bits |
wrap | SubtleCrypto::wrap_key, unwrap_key |
full | All 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());
// 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824Non-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.