MD5 in erlang.

Vladimir Sekissov svg@REDACTED
Wed Mar 26 19:32:19 CET 2003


Good day,

jeinhorn> I was wondering if erlang had any built-in tools to generate an MD5 Hash
jeinhorn> that looks similiar what is generated by md5sum on linux.

jeinhorn> erlang:md5("hello").
jeinhorn> <<93,65,64,42,188,75,42,118,185,113,157,145,16,23,197,146>>

At first your must call:

erlang:md5("hello\n").

if you want your md5 sum be equal to output of `md5sum'
Add hoc solution:

hex(L) when list (L) ->
  lists:flatten([hex(I) || I <- L]);
hex(I) when I > 16#f ->
  [hex0((I band 16#f0) bsr 4), hex0((I band 16#0f))];
hex(I) -> [$0, hex0(I)].

hex0(10) -> $a;
hex0(11) -> $b;
hex0(12) -> $c;
hex0(13) -> $d;
hex0(14) -> $e;
hex0(15) -> $f;
hex0(I) ->  $0 +I.

5> test:hex(erlang:md5("hello\n")).
"b1946ac92492d2347c6235b4d2611184"

Best Regards,
Vladimir Sekissov



More information about the erlang-questions mailing list