KeyGenerator is a PBKDF2 implementation for Elixir. Conforming to rfc2898.
It can be used to derive a number of keys for various purposes from a given secret. This lets applications have a single secure secret, but avoid reusing that key in multiple incompatible contexts.
defmodule User do
import KeyGenerator
def encrypt_password(password, salt, opts \\ []) do
generate(password, salt, opts) |> to_hex
end
end
key = User.encrypt_password("password", "salt")
# => "f87cbb89d972a9b96f5a9e2068308f06e1cf6421748..."
:iterations
- defaults to 1000;:length
- a length in octets for the derived key. Defaults to 64;:digest
- an hmac function to use as the pseudo-random function. Defaults to:sha
;