[erlang-questions] crypto:md5/1 vs openssl md5

Sverker Eriksson sverker@REDACTED
Fri Feb 10 11:57:31 CET 2012


Don't seem to me like "openssl md5" command expects a hexstring, but 
rather the raw data itself.


 > echo Hello > Hello
 > hexdump -C Hello
00000000  48 65 6c 6c 6f 0a                                 |Hello.|
00000006
 > cat Hello | openssl md5
09f7e02f1290be211da707a266f153b3
 > erl
Erlang R15B (erts-5.9.0.1) [64-bit] [smp:4:4] [async-threads:0] 
[kernel-poll:false]

Eshell V5.9.0.1  (abort with ^G)
1> crypto:md5(<<"Hello\n">>).
<<9,247,224,47,18,144,190,33,29,167,7,162,102,241,83,179>>

/Sverker, Erlang/OTP


CGS wrote:
> Hi,
>
> Just for my curiosity, does anybody know if crypto:md5/1 in R14B03 is
> intentionally different from openssl md5? (The sha matches perfectly.)
>
> Just a short test (Erlang shell):
> 1> RB =
> crypto:rand_bytes(16).
> <<141,190,84,7,129,230,147,112,200,205,68,80,240,78,68,198>>
>
> 2> MD5 =
> crypto:md5(RB).
> <<97,59,0,195,229,254,195,237,238,126,156,14,33,142,206,183>>
> 3> lists:flatten(lists:map(fun([X,Y])->[case X>64 of true -> X+32; false->
> X end,case Y>64 of true -> Y+32; false -> Y end];([X])->[$0,case X>64 of
> true -> X+32; false -> X end] end, lists:map(fun(X)->integer_to_list(X,16)
> end, binary_to_list(RB)))).
> "8dbe540781e69370c8cd4450f04e44c6"
> 4> lists:flatten(lists:map(fun([X,Y])->[case X>64 of true -> X+32; false->
> X end,case Y>64 of true -> Y+32; false -> Y end];([X])->[$0,case X>64 of
> true -> X+32; false -> X end] end, lists:map(fun(X)->integer_to_list(X,16)
> end, binary_to_list(MD5)))).
> "613b00c3e5fec3edee7e9c0e218eceb7"
> 5> os:cmd("echo \"8dbe540781e69370c8cd4450f04e44c6\" | openssl
> md5").
> "(stdin)=
> 6007d8f36b589078f3565b5c90cedffc\n"
>
> As you can see the same rand number, "8dbe540781e69370c8cd4450f04e44c6",
> gives in crypto:md5 "613b00c3e5fec3edee7e9c0e218eceb7" while in openssl md5
> "6007d8f36b589078f3565b5c90cedffc". Please, let me know if I do something
> wrong.
>
> CGS
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>   





More information about the erlang-questions mailing list