2016-10-08 15:34:51 +00:00
|
|
|
defmodule Crypto do
|
|
|
|
def md5(data) do
|
|
|
|
Base.encode16(:erlang.md5(data), case: :lower)
|
|
|
|
end
|
2017-06-12 09:52:50 +00:00
|
|
|
|
|
|
|
def random_token(length) do
|
|
|
|
length
|
|
|
|
|> :crypto.strong_rand_bytes
|
|
|
|
|> Base.url_encode64
|
|
|
|
|> String.replace(~r/[_=-]/, "")
|
|
|
|
|> binary_part(0, length)
|
|
|
|
end
|
2016-10-08 15:34:51 +00:00
|
|
|
end
|