Skip to content

Instantly share code, notes, and snippets.

@10nin
Created June 5, 2013 12:00
Show Gist options
  • Save 10nin/5713402 to your computer and use it in GitHub Desktop.
Save 10nin/5713402 to your computer and use it in GitHub Desktop.
Get message digest generally by elixir-lang.
defmodule Crypto do
def gethash(typ, s) do
list_to_binary(Enum.map(bitstring_to_list(:crypto.hash(typ, s)), fn(x) -> integer_to_binary(x, 16) end))
end
def sha1(s), do: gethash(:sha, s)
def md5(s), do: gethash(:md5, s)
def sha256(s), do: gethash(:sha256, s)
def sha512(s), do: gethash(:sha512, s)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment