public string GetMD5Hash(string input)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
string password = s.ToString();
return password;
}
Thursday, April 09, 2009
Subscribe to:
Post Comments (Atom)
4 comments:
just so you know (in case you don't) use of MD5 should be restricted to interacting with legacy systems...
use of MD5 in new systems has been deprecated since the mid 90's because of security problems with the algorithm - SHA1 is the suggested replacement... NIST is in the process of selecting a new standard secure hash algorithm (since problems with SHA1 have also started to surface) but until that's done SHA1 is still the standard...
Thank you for the tips. I was just trying to get a unique hash key for long string text.
ah, well in that case MD5 should be just fine... in fact, even CRC's should work (and be faster), though i don't know if there's a handy .Net class for generating those...
There is a GetHashCode method in string but not certain it guarantees unique.
Post a Comment