gossamer/subtle_crypto
Values
pub fn decrypt(
algorithm: encrypt_algorithm.EncryptAlgorithm,
key: crypto_key.CryptoKey,
data: uint8_array.Uint8Array,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Decrypts previously encrypted data using a cryptographic key.
pub fn derive_bits(
algorithm: derive_algorithm.DeriveAlgorithm,
base_key: crypto_key.CryptoKey,
length: Int,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Derives an array of bits from a base key using a cryptographic algorithm.
pub fn derive_key(
algorithm: derive_algorithm.DeriveAlgorithm,
base_key: crypto_key.CryptoKey,
derived_key_type: derived_key_type.DerivedKeyType,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Derives a secret key from a base or master key using a cryptographic algorithm.
pub fn digest(
algorithm: String,
data: uint8_array.Uint8Array,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Computes a cryptographic hash (digest) of the given data.
This method is commonly used for verifying data integrity.
pub fn encrypt(
algorithm: encrypt_algorithm.EncryptAlgorithm,
key: crypto_key.CryptoKey,
data: uint8_array.Uint8Array,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Encrypts data using a cryptographic key.
This method is used with both symmetric (AES) and asymmetric (RSA) encryption.
pub fn export_key(
format: key_format.KeyFormat,
key: crypto_key.CryptoKey,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Exports a cryptographic key in raw, PKCS8, or SPKI format.
This method is used to export symmetric keys (AES), private keys (PKCS8), or public keys (SPKI) in binary form.
pub fn export_key_jwk(
key: crypto_key.CryptoKey,
) -> promise.Promise(Result(dynamic.Dynamic, String))
Exports a cryptographic key in JSON Web Key (JWK) format.
This method allows exporting an asymmetric key (e.g., RSA, ECDSA) into a JSON-based representation, making it easy to store and transfer across systems.
pub fn generate_key(
algorithm: key_gen_algorithm.KeyGenAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Generates a symmetric cryptographic key for encryption, authentication, or hashing.
pub fn generate_key_pair(
algorithm: key_pair_gen_algorithm.KeyPairGenAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(
Result(crypto_key_pair.CryptoKeyPair, String),
)
Generates an asymmetric cryptographic key pair for encryption, signing, or key exchange.
pub fn import_key(
format: key_format.KeyFormat,
key_data: uint8_array.Uint8Array,
algorithm: import_algorithm.ImportAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Imports a cryptographic key in raw, PKCS8, or SPKI format.
This method is used to import symmetric keys (e.g., AES), private keys (PKCS8), or public keys (SPKI).
pub fn import_key_jwk(
key_data: dynamic.Dynamic,
algorithm: import_algorithm.ImportAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Imports a cryptographic key in JSON Web Key (JWK) format.
This method is used to import an asymmetric key (e.g., RSA or ECDSA) from a JWK object. JWK allows structured representation of keys, making them portable across different systems.
pub fn sign(
algorithm: sign_algorithm.SignAlgorithm,
key: crypto_key.CryptoKey,
data: uint8_array.Uint8Array,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Generates a digital signature using a private cryptographic key.
This method is used to sign data with an asymmetric key (e.g., RSA-PSS, ECDSA).
pub fn unwrap_key(
format: key_format.KeyFormat,
wrapped_key: uint8_array.Uint8Array,
unwrapping_key: crypto_key.CryptoKey,
unwrap_algorithm: wrap_algorithm.WrapAlgorithm,
unwrapped_key_algorithm: import_algorithm.ImportAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Unwraps (decrypts) a previously wrapped key.
pub fn unwrap_key_jwk(
wrapped_key: uint8_array.Uint8Array,
unwrapping_key: crypto_key.CryptoKey,
unwrap_algorithm: wrap_algorithm.WrapAlgorithm,
unwrapped_key_algorithm: import_algorithm.ImportAlgorithm,
extractable: Bool,
usages: List(key_usage.KeyUsage),
) -> promise.Promise(Result(crypto_key.CryptoKey, String))
Unwraps (decrypts) a previously wrapped key from JWK format.
pub fn verify(
algorithm: sign_algorithm.SignAlgorithm,
key: crypto_key.CryptoKey,
signature: uint8_array.Uint8Array,
data: uint8_array.Uint8Array,
) -> promise.Promise(Result(Bool, String))
Verifies a digital signature using a public cryptographic key.
This method checks whether a signature is valid for the given data.
pub fn wrap_key(
format: key_format.KeyFormat,
key: crypto_key.CryptoKey,
wrapping_key: crypto_key.CryptoKey,
algorithm: wrap_algorithm.WrapAlgorithm,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Wraps (encrypts) a cryptographic key for secure storage or transmission.
pub fn wrap_key_jwk(
key: crypto_key.CryptoKey,
wrapping_key: crypto_key.CryptoKey,
algorithm: wrap_algorithm.WrapAlgorithm,
) -> promise.Promise(Result(array_buffer.ArrayBuffer, String))
Wraps (encrypts) a cryptographic key to JWK format for secure storage or transmission.