In Elixir you can get the md5 of a string:
ex(1)> :crypto.hash(:md5 , "Elixir") |> Base.encode16()
"A12EB062ECA9D1E6C69FCF8B603787C3"
But why does not return the same value from Terminal?
[~ ~]$echo 'Elixir' | md5
694f56f4b30e60837151723777795fc2
Sure I'm missing something.
The echo
command will include a new line:
iex>:crypto.hash(:md5, "Elixir\n") |> Base.encode16()
"694F56F4B30E60837151723777795FC2"
You can use case
to modify the case of Base.encode16:
iex>:crypto.hash(:md5, "Elixir\n") |> Base.encode16(case: :lower)
"694f56f4b30e60837151723777795fc2"
You can use the -n
flag with echo
to prevent the new line:
$ echo -n 'Elixir' | md5sum
a12eb062eca9d1e6c69fcf8b603787c3 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With