Erlang Equivalent of C# Hash

Joakim G. jocke@REDACTED
Thu Dec 22 23:39:05 CET 2005


and yes

To compare the digests you have to do something like this on
the Erlang side:

     Context = erlang:md5_init(),
     NewContext = erlang:md5_update(Context, String),
     base64:str_2_base64(binary_to_list(erlang:md5_final(NewContext)))

/Jocke

PS http://www.sics.se/~joe/bluetail/eol/base64.erl DS

Joakim G. wrote:
> Jing Ding wrote:
> 
>> Hi there,
>> I previously asked about how to do MD5. And I got answers.
>> Thanks for your help. But the binary result is not the same as the 
>> string generated from C# :
>> ------------------------------------------------------
>> byte[] a = md5Hash.ComputeHash(AE.GetBytes(UserID + value));
>> PasswordHash = Convert.ToBase64String(a);
>> ---------------------------------------------------
>> Anyone else happen to came across this? Thanks.
> 
> 
> Do like this in C#:
> 
> ==
> 
>     byte[] buffer = System.Text.Encoding.Default.GetBytes(String);
>     System.Security.Cryptography.MD5CryptoServiceProvider Check;
>     Check = new System.Security.Cryptography.MD5CryptoServiceProvider();
>     byte[] Hash = Check.ComputeHash(buffer);
>     string HashString = "";
>     foreach (byte a in Hash) {
>         if (a < 16) {
>             HashString += "0" + a.ToString("X");
>         } else {
>             HashString += a.ToString("X");
>         }
>     }
>     return HashString.ToLower();
> 
> ==
> 
> and it works with Erlang's md5 engine and Perl's CPAN
> md5_base64 (in Digest::MD5::Perl) out of the box.
> 
> If you like a pragmatic answer. This is it. :-)
> 
> Cheers
> /Jocke


-- 
tail-f - Caps lock is nowhere and everything is under control.



More information about the erlang-questions mailing list