Skip to content

CryptoOutput

Wrapper around raw bytes returned by cryptographic operations (sign, encrypt, digest, export_key, derive_bits, wrap_key).

Methods

MethodReturn typeDescription
to_bytes()&[u8]Raw bytes as a slice
to_vec()Vec<u8>Consumes self, returns owned bytes
to_hex()StringLowercase hex encoding
to_base64()StringStandard base64 with padding
to_base64url()StringURL-safe base64 without padding

Example

rust
let hash = subtle.digest(Hash::Sha256, b"hello").await?;

// As hex
assert_eq!(hash.to_hex(), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824");

// As base64url (useful for JWT signatures)
let sig = subtle.sign(&algorithm, &key, data).await?;
let jwt_sig = sig.to_base64url();