Module Brr_webcrypto.Subtle_crypto

SubtleCrypto objects

type t

The type for SubtleCrypto objects.

val encrypt : t -> Crypto_algo.t -> Crypto_key.t -> ('a'b) Brr.Tarray.t -> Brr.Tarray.Buffer.t Fut.or_error

encrypt s a k data is data encrypted with key k and algorithm a.

val decrypt : t -> Crypto_algo.t -> Crypto_key.t -> ('a'b) Brr.Tarray.t -> Brr.Tarray.Buffer.t Fut.or_error

decrypt s a k data is data decrypted with key k and algorithm a.

val digest : t -> Crypto_algo.t -> ('a'b) Brr.Tarray.t -> Brr.Tarray.Buffer.t Fut.or_error

digest s a data is the digest of data according to algorithm a.

Signatures

val sign : t -> Crypto_algo.t -> Crypto_key.t -> ('a'b) Brr.Tarray.t -> Brr.Tarray.Buffer.t Fut.or_error

sign s a k data is the signature of data with key k and algorithm a.

val verify : t -> Crypto_algo.t -> Crypto_key.t -> sig':('a'b) Brr.Tarray.t -> ('c'd) Brr.Tarray.t -> bool Fut.or_error

verify s a k ~sig' data is true iff the signature of data with key k and algorithm a matches sig'.

Key generation

val generate_key : t -> Crypto_algo.t -> extractable:bool -> usages:Crypto_key.Usage.t list -> Crypto_key.t Fut.or_error

generate_key s a ~extractable ~usage is a key generated for algorithm a and usages usages. Warning if the algorithm generates a key pair use generate_key_pair.

val generate_key_pair : t -> Crypto_algo.t -> extractable:bool -> usages:Crypto_key.Usage.t list -> Crypto_key.pair Fut.or_error

generate_key s a ~extractable ~usage is a key generated of type and parameters a and usages usages. Warning if the algorithm generates a single key use generate_key.

Key derivation

val derive_bits : t -> Crypto_algo.t -> Crypto_key.t -> int -> Brr.Tarray.Buffer.t Fut.or_error

derive_bits s a k l are l bits derived from k with algorithm a.

val derive_key : t -> Crypto_algo.t -> Crypto_key.t -> derived:Crypto_algo.t -> extractable:bool -> usages:Crypto_key.Usage.t list -> Crypto_key.t Fut.or_error

derive_key s a k ~derived_type ~extractable ~usages is a key of type and parameters ~derived and usages usages derived from key k of type and parameters a.

Key encoding and decoding

val export_key : t -> Crypto_key.Format.t -> Crypto_key.t -> [ `Buffer of ('a'b) Brr.Tarray.t | `Json_web_key of Brr.Json.t ] Fut.or_error

export_key s f k is the key k exported in format f. `Json_web_key is only returned if Crypto_key.Format.jwk is specified.

val import_key : t -> Crypto_key.Format.t -> [ `Buffer of ('a'b) Brr.Tarray.t | `Json_web_key of Brr.Json.t ] -> Crypto_algo.t -> extractable:bool -> usages:Crypto_key.Usage.t list -> Crypto_key.t Fut.or_error

import_key s f k a ~extractable ~usage is the key k imported from format f and type a used for usages.

val wrap_key : t -> Crypto_key.Format.t -> Crypto_key.t -> wrap_key:Crypto_key.t -> wrapper:Crypto_algo.t -> Brr.Tarray.Buffer.t Fut.or_error

wrap_key s f k ~wrap_key ~wrapper is like export_key but encrypts the result with wrap_key ad algorithm wrapper.

val unwrap_key : t -> Crypto_key.Format.t -> ('a'b) Brr.Tarray.t -> wrap_key:Crypto_key.t -> wrapper:Crypto_algo.t -> unwrapped:Crypto_algo.t -> extractable:bool -> usages:Crypto_key.Usage.t list -> Crypto_key.t Fut.or_error

unwrap_key s f b ~wrap_key ~wrapper ~unwrapped ~extractable ~usages is like import_key but unwraps the wrapper of b made wtih wrap_key and algorithm wrapped.