Paseto (paseto v1.5.0)
Main entry point for consumers. Will parse the provided payload and return a version (currently only v1 and v2 exist) struct.
Tokens are broken up into several components:
- version: v1 or v2 -- v2 suggested
- purpose: Local or Public -- Local -> Symmetric Encryption for payload & Public -> Asymmetric Encryption for payload
- payload: A signed or encrypted & b64 encoded string
- footer: An optional value, often used for storing keyIDs or other similar info.
Link to this section Summary
Functions
Handles generating a token
Handles parsing a token. Providing it just the entire token will return the
Paseto.Token
struct with all fields populated.
Link to this section Functions
Link to this function
generate_token(version, purpose, payload, secret_key, footer \\ "")
@spec generate_token(String.t(), String.t(), String.t(), binary(), String.t()) :: String.t() | {:error, String.t()}
Handles generating a token:
Tokens are broken up into several components:
- version: v1 or v2 -- v2 suggested
- purpose: Local or Public -- Local -> Symmetric Encryption for payload & Public -> Asymmetric Encryption for payload
- payload: A signed or encrypted & b64 encoded string
- footer: An optional value, often used for storing keyIDs or other similar info.
Examples:
iex> {:ok, pk, sk} = Salty.Sign.Ed25519.keypair()
iex> token = generate_token("v2", "public", "This is a test message", sk)
"v2.public.VGhpcyBpcyBhIHRlc3QgbWVzc2FnZSe-sJyD2x_fCDGEUKDcvjU9y3jRHxD4iEJ8iQwwfMUq5jUR47J15uPbgyOmBkQCxNDydR0yV1iBR-GPpyE-NQw"
iex> Paseto.parse_token(token, pk)
{:ok,
%Paseto.Token{
footer: nil,
payload: "This is a test message",
purpose: "public",
version: "v2"
}}
Link to this function
parse_token(token, public_key)
Handles parsing a token. Providing it just the entire token will return the
Paseto.Token
struct with all fields populated.
Examples:
iex> token = "v2.public.VGhpcyBpcyBhIHRlc3QgbWVzc2FnZSe-sJyD2x_fCDGEUKDcvjU9y3jRHxD4iEJ8iQwwfMUq5jUR47J15uPbgyOmBkQCxNDydR0yV1iBR-GPpyE-NQw"
iex> Paseto.parse_token(token, pk)
{:ok,
%Paseto.Token{
footer: nil,
payload: "This is a test message",
purpose: "public",
version: "v2"
}}
Link to this function