Snippets
MD5 hash
Calculate the MD5 hash of a given string
// Some namespaces needed using System.Security.Cryptography; using System.Text; public string MD5(string input) { MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); byte[] bs = Encoding.UTF8.GetBytes(input); bs = x.ComputeHash(bs); StringBuilder s = new StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } return s.ToString(); }
posted by Christoff Truter on 2009-06-02 14:08:47
Comments
byte[] bs = Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
StringBuilder s = new StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToString());
comment posted by Anonymous on 2009-12-08 07:26:37
Alternative MD5
a static method called HashPasswordForStoringInConfigFile, where one can
also retrieve a md5 (or sha1) hash in the following manner:
FormsAuthentication.HashPasswordForStoringInConfigFile("somepassword", "md5");
comment posted by Christoff Truter on 2009-06-02 20:04:38