FormsAuthentication.HashPasswordForStoringInConfigFile() continued…

.NET General 1 Comment

In "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));
}

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"));

One Response to “FormsAuthentication.HashPasswordForStoringInConfigFile() continued…”

  1. Veggerby : IBlog » Blog Archive » MD5 Extension Method Says:
    September 29th, 2009 at 14:43

    [...] A nifty little extension method that generated the MD5/SHA-1 hash of a string. These methods are a continuation of my previous post: [...]

Leave a Reply

Icons by N.Design Studio. Designed By Ben Swift. Powered by WordPress, Search Optimization and Free WordPress Themes
Entries RSS Comments RSS Log in