Available since v0.6.0
local fernet = require "fernet"
Fernet provides symmetric-authenticated-encryption with an API that makes misusing it difficult. It is based on a public specification and there are interoperable implementations in Rust, Python, Ruby, JavaScript, Go, and many others.
local key = fernet.genkey() -- Store this somewhere safe
local f = fernet(key)
local secret = "my secret message"
local encrypted = f:encrypt(secret)
local decrypted = f:decrypt(encrypted)
assert(secret == decrypted)
local encrypted = f:encrypt(secret) -- the current timestamp is stored in the token
local decrypted = f:decrypt(encrypted) -- the token is valid forever
local decrypted_ttl = f:decrypt(encrypted, 10) -- the token is valid for 10 seconds
NOTE:
key
must be 32-bytes, url-safe base64-encodedttl
is in seconds