OptimusId v0.1.0 OptimusId.Secret View Source

Holds secret & unique data required for encoding and decoding with the library.

Usage

Start by generating the secret (choose large prime number that fits in 4-byte integer):

secret = OptimusId.Secret.generate(2078493839)

Depending on your application and approach towards security you may choose one of following approaches towards storing the newly generated secret:

  • use the tuple representation directly (e.g. if the secret will be hardcoded into source code or stored in database with support for Erlang terms like ETS)

  • store string representation yielded by OptimusId.Secret.to_string/1 and convert it back to tuple representation (e.g. if using env vars or arbitrary secret vault)

For improved security you may choose to use multiple secrets (e.g. one per API resource).

Link to this section Summary

Functions

Generates new random secret based on 32-bit prime number.

Converts secret tuple to string representation (useful for storage in env var or vault).

Link to this section Types

Link to this section Functions

Generates new random secret based on 32-bit prime number.

Note that generated secret will be different even for the same input prime number.

Link to this function

to_string(tuple) View Source
to_string(t()) :: String.t()

Converts secret tuple to string representation (useful for storage in env var or vault).

Note that OptimusId doesn't use the string version for performance reasons and since libraries are not available in config/*.exs you'll have to convert it yourself e.g. with following code in config/releases.exs:

secret_string = System.fetch_env!("MY_SECRET")

secret_tuple =
  secret_string
  |> String.split("-")
  |> Enum.map(&String.to_integer/1)
  |> List.to_tuple

config :my_app, :my_secret, secret_tuple