asciinema.org/lib/asciinema/crypto.ex
2017-06-12 11:52:50 +02:00

14 lines
273 B
Elixir

defmodule Crypto do
def md5(data) do
Base.encode16(:erlang.md5(data), case: :lower)
end
def random_token(length) do
length
|> :crypto.strong_rand_bytes
|> Base.url_encode64
|> String.replace(~r/[_=-]/, "")
|> binary_part(0, length)
end
end