LoginSignup
4
0

More than 5 years have passed since last update.

Elixir で md5 暗号化

Posted at

特に必要はなかったのだが、ちょっとお試しで書いてみた。
ちなみに、erlang20.0 で、crypto:md5/1 は廃止されているようなので、crypto:hash/2 を使用するようだ。

crypto:md5/1 will fail, since it was removed in 20.0; use crypto:hash/2
crypto.ex
defmodule Crypto do
    def convert_md5 do
    #   :crypto.md5("Whoocus") 非推奨
      :crypto.hash(:md5, "Whoocus")
        |> Base.encode16(case: :lower)
    end
end

また、そのままだとバイナリで表示されてしまう。

iex(1)> Crypto.convert_md5
<<254, 97, 249, 200, 73, 189, 91, 193, 23, 19, 37, 187, 163, 17, 159, 144>>

そのため、Base.encode16 で文字列化すること。

iex(2)> Crypto.convert_md5
"fe61f9c849bd5bc1171325bba3119f90"

参考URL: http://www.whoocus.com/blog/?p=2659

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0