casper

An interface to the ChaCha20-Poly1305 symmetric cipher via Erlang and Node libraries. The “with” variants allow you to add additional authenticated data AAD which is required for encryption and decryption.

Values

pub fn decrypt(
  input: BitArray,
  key: BitArray,
) -> Result(BitArray, Nil)

Given a BitArray (the output from encrypt) and a 32 byte encryption key attempt to decrypt the input.

This method will return Error(Nil) if it is unable to decrypt the input. This will happen if you don’t call encrypt first.

The javascript target uses Node’s crypto library and will not work on the web.

pub fn decrypt_with(
  input: BitArray,
  associated_data: BitArray,
  key: BitArray,
) -> Result(BitArray, Nil)

See decrypt. This method additionally accepts additional authenticated data.

pub fn encrypt(
  input: BitArray,
  key: BitArray,
) -> Result(BitArray, Nil)

Given a BitArray and a 32 byte encryption key, generated via gleam/crypto strong_random_bytes method, encrypt the input via ChaCha20-Poly1305. The output BitArray is encoded especially for this cipher.

This method will return Error(Nil) if you provide a non-32 byte key.

The javascript target uses Node’s crypto library and will not work on the web.

pub fn encrypt_with(
  input: BitArray,
  associated_data: BitArray,
  key: BitArray,
) -> Result(BitArray, Nil)

See encrypt. This method additionally accepts additional authenticated data.

Search Document