Skip to content

Instantly share code, notes, and snippets.

@danj3
Last active March 26, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danj3/a4fd7dc390bb2fac59495140905a53ad to your computer and use it in GitHub Desktop.
Save danj3/a4fd7dc390bb2fac59495140905a53ad to your computer and use it in GitHub Desktop.
Elixir: create an armored sha256 hash of an input
defmodule HashSignature do
@doc """
encode input to a sha256 and output as an armored string.
results should be fully portable and consistent with other
tools.
"""
def get( input ) do
:crypto.hash( :sha256, input )
|> :crypto.bytes_to_integer
|> (fn i -> :io_lib.format("~64.16.0b",[i]) |> hd end ).()
|> to_string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment