Skip to content

SubtleCrypto

Wrapper for the crypto.subtle interface. Each method is gated behind a feature flag.

Constructor

rust
let subtle = SubtleCrypto::new()?;

Methods

Digest (digest feature)

MethodSignature
digestasync fn digest(&self, hash: Hash, data: &[u8]) -> Result<CryptoOutput>

Sign / Verify (sign feature)

MethodSignature
signasync fn sign(&self, algorithm: &Algorithm, key: &CryptoKey, data: &[u8]) -> Result<CryptoOutput>
verifyasync fn verify(&self, algorithm: &Algorithm, key: &CryptoKey, signature: &[u8], data: &[u8]) -> Result<bool>

Encrypt / Decrypt (encrypt feature)

MethodSignature
encryptasync fn encrypt(&self, algorithm: &Algorithm, key: &CryptoKey, data: &[u8]) -> Result<CryptoOutput>
decryptasync fn decrypt(&self, algorithm: &Algorithm, key: &CryptoKey, data: &[u8]) -> Result<CryptoOutput>

Key Management (key feature)

MethodSignature
import_keyasync fn import_key(&self, format: KeyFormat, key_data: &[u8], algorithm: &Algorithm, extractable: bool, usages: &[KeyUsage]) -> Result<CryptoKey>
export_keyasync fn export_key(&self, format: KeyFormat, key: &CryptoKey) -> Result<CryptoOutput>
generate_keyasync fn generate_key(&self, params: &GenerateKeyParams, extractable: bool, usages: &[KeyUsage]) -> Result<GenerateKeyResult>

Key Derivation (derive feature)

MethodSignature
derive_keyasync fn derive_key(&self, algorithm: &Algorithm, base_key: &CryptoKey, derived_key_type: &GenerateKeyParams, extractable: bool, usages: &[KeyUsage]) -> Result<CryptoKey>
derive_bitsasync fn derive_bits(&self, algorithm: &Algorithm, base_key: &CryptoKey, length: u32) -> Result<CryptoOutput>

Key Wrapping (wrap feature)

MethodSignature
wrap_keyasync fn wrap_key(&self, format: KeyFormat, key: &CryptoKey, wrapping_key: &CryptoKey, algorithm: &Algorithm) -> Result<CryptoOutput>
unwrap_keyasync fn unwrap_key(&self, format: KeyFormat, wrapped_key: &[u8], unwrapping_key: &CryptoKey, unwrap_algorithm: &Algorithm, unwrapped_key_algorithm: &Algorithm, extractable: bool, usages: &[KeyUsage]) -> Result<CryptoKey>