View Source Charon.Utils.Crypto (Charon v2.7.0)

Encrypt/decrypt, sign/verify, secure compare binaries etc.

Link to this section Summary

Functions

Constant time memory comparison for fixed length binaries, such as results of HMAC computations.

Decrypt a binary using the provided key and return the plaintext or an error.

Encrypt the plaintext into a binary using the provided key.

Calculate a HMAC of data using key. The algorithm is sha256.

Generate a random URL-encoded string of byte_size bytes.

Link to this section Functions

Link to this function

constant_time_compare(bin_a, bin_b)

View Source
@spec constant_time_compare(binary(), binary()) :: boolean()

Constant time memory comparison for fixed length binaries, such as results of HMAC computations.

Returns true if the binaries are identical, false if they are of the same length but not identical. The function raises an error:badarg exception if the binaries are of different size.

@spec decrypt(binary(), binary()) :: {:ok, binary()} | {:error, :decryption_failed}

Decrypt a binary using the provided key and return the plaintext or an error.

@spec encrypt(binary(), binary()) :: binary()

Encrypt the plaintext into a binary using the provided key.

@spec hmac(iodata(), binary()) :: binary()

Calculate a HMAC of data using key. The algorithm is sha256.

Link to this function

random_url_encoded(byte_size)

View Source
@spec random_url_encoded(pos_integer()) :: binary()

Generate a random URL-encoded string of byte_size bytes.