Erlang Equivalent of C# Hash
Joakim G.
jocke@REDACTED
Thu Dec 22 21:52:04 CET 2005
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
More information about the erlang-questions
mailing list