fernetex v0.1.0 Fernet
Generate or verify Fernet tokens based on https://github.com/fernet/spec
Example
Fernet generates an encrypted ciphertext from plaintext using the supplied 256-bit secret:
iex> secret = "lBrMpXneb47e_iY4RFA-HhF2vk2zeL4smfijX-y02-g="
iex> plaintext = "Hello, world!"
iex> {:ok, _iv, ciphertext} = Fernet.generate(plaintext, secret: secret)
iex> {:ok, ^plaintext} = Fernet.verify(ciphertext, secret: secret)
{:ok, "Hello, world!"}
A TTL can optionally be supplied during decryption to reject stale messages:
iex> secret = "lBrMpXneb47e_iY4RFA-HhF2vk2zeL4smfijX-y02-g="
iex> plaintext = "Hello, world!"
iex> {:ok, _iv, ciphertext} = Fernet.generate(plaintext, secret: secret)
iex> Fernet.verify(ciphertext, secret: secret, ttl: 0)
** (RuntimeError) expired TTL
Summary
Functions
Generate a token for the given message using the secret to encrypt it
Verify a token using the given secret and optionally validate TTL
Types
generate_options ::
[{:secret, String.t}] |
%{secret: String.t}
iv :: binary
verify_options ::
[secret: String.t, ttl: integer, enforce_ttl: boolean] |
%{secret: String.t, ttl: integer, enforce_ttl: boolean}
Functions
Specs
generate(plaintext, generate_options) :: {:ok, iv, ciphertext}
Generate a token for the given message using the secret to encrypt it.
Options
The accepted options are:
:secret
- secret to use for encryptions (256 bits, defaults to`FERNET_SECRET` environment variable)
Specs
verify(ciphertext, verify_options) :: {:ok, plaintext}
Verify a token using the given secret and optionally validate TTL
Options
The accepted options are:
:secret
- secret to use for encryptions (256 bits, defaults to`FERNET_SECRET` environment variable)
:ttl
- If:enforce_ttl
is true then this is the time inseconds (defaults to 60 seconds)
:enforce_ttl
- Should ttl be enforced (default to true)