casper
Casper is an opinionated symmetric cipher library which offers ChaCha20-Poly1305 via Erlang or Node.
Note: the javascript
target will not work in a browser environment. The bun
and deno
runtimes are not supported.
Get the library
gleam add casper@2
Using the library
import casper
pub fn main() -> Nil {
let key = casper.new_key()
let encrypted = casper.encrypt(<<"casper">>, key)
let assert Ok(decrypted) = casper.decrypt(encrypted, key)
// ...
}
Generating a key for your environment
If you want to generate a key to store in your environment run gleam run -m casper
. It will generate a base64 encoded string which you can read via
envoy.get
. Use casper.from_base64
to turn the String
into a
SecretKey
which you can use for cipher operations.
Hex documentation
Further documentation can be found at https://hexdocs.pm/casper.
Development
gleam run # Run the project
gleam test # Run the tests on Erlang
gleam test -t javascript # Run the tests on Node