Fernet

    Available since v0.6.0

    Easy, safe symmetric encryption

    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)
    

    Encrypted token expiry

    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-encoded
    • ttl is in seconds