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.
Types
Values
pub fn decrypt(
message input: BitArray,
key secret: SecretKey,
) -> Result(BitArray, Nil)
Given a BitArray (the output from encrypt) and a SecretKey
attempt to decrypt the message.
This method will return Error(Nil) if it is unable to decrypt the input.
This might happen if you don’t call encrypt first.
The javascript target uses Node’s crypto library and will not work on the web. The bun and deno runtimes are not supported.
pub fn decrypt_with(
message input: BitArray,
associated_data associated_data: BitArray,
key secret: SecretKey,
) -> Result(BitArray, Nil)
See decrypt. This method uses additional authenticated data to decrypt
the message.
pub fn encrypt(
message input: BitArray,
key secret: SecretKey,
) -> BitArray
Given a BitArray message and a SecretKey encrypt the message via
ChaCha20-Poly1305. The output BitArray is encoded especially for this
cipher.
The javascript target uses Node’s crypto library and will not work on the web. Currently bun and deno runtimes are unsupported.
pub fn encrypt_with(
message input: BitArray,
associated_data associated_data: BitArray,
key secret: SecretKey,
) -> BitArray
See encrypt. This method adds additional authenticated data to the message
for encryption.
pub fn from_bytes(input: BitArray) -> Result(SecretKey, Nil)
Attempt to convert a BitArray into a SecretKey. This is useful when you
want to read an encryption key from your environment. For example, you could
store a base64 encoded secret as an environment variable. In the Erlang
shell, base64:encode(crypto:strong_rand_bytes(32)).
If you don’t provide 32 bytes it will return Error(Nil).