FormsAuthentication.HashPasswordForStoringInConfigFile() continued…
July 27th, 2008.NET General 1 CommentIn "response" to my own previous post: two little extension methods that does exactly what "we" need:
public static string GetHashValue(this MD5 hash, string value)
{
return GetHashValue(hash, Encoding.UTF8.GetBytes(value));
}
{
return GetHashValue(hash, Encoding.UTF8.GetBytes(value));
}
public static string GetHashValue(this MD5 hash, byte[] value)
{
byte[] data = hash.ComputeHash(value);
string md5 = "";
for (int i = 0; i < data.Length; i++)
{
md5 += data[i].ToString("x2").ToLowerInvariant();
}
return md5;
}
Usage:
MD5 md5 = MD5.Create();
Console.WriteLine(md5.GetHashValue("test"));
Console.WriteLine(md5.GetHashValue("test"));
Recent Comments