token v0.1.1 Token
Functions for generating and hashing strings
Configuration
The module can be configured under the :token
namespace
with the following options:
:algorithm
– A hashing algorithm, can be either::md5
,:sha
,:sha224
,:sha256
,:sha384
,:sha512
:secret
– A secret is used to sign a hash (required)
Example config/config.exs
:
config :token,
algorithm: :sha256,
token: "token_secret"
Link to this section Summary
Functions
Generates a cryptographically secure pseudorandom string
Hashes the passed string with a secret
Link to this section Functions
Generates a cryptographically secure pseudorandom string
This function generates bytes using the
:crypto.strong_rand_bytes/1
function and the bytes
are converted into a hexadecimal string.
The result is 64 characters long
Hashes the passed string with a secret
The hash is signed using HMAC with the algorithm
defined in the configuration file.
The default algorithm is :sha512
To be able to hash, you need to define a secret in your configuration file. See also Configuration.
This function is not intended to hash passwords,
or any user-passed string. If you are looking
for a way to hash passwords, use Comeonin.Bcrypt
,
or Comeonin.Argon2
.