Welcome to weblogs.com.pk Sign in | Join | Help

MD5 hashing

.NET base class library is very rich. Here is the code snippet which hashes the give data. It’s recommended to store the hash of the sensitive data like user’s password.

 

public static string GetMD5Hash(string data)

{

            System.Text.Encoder enc = System.Text.Encoding.ASCII.GetEncoder();

            byte[] bs = new byte[data.Length];

            enc.GetBytes(data.ToCharArray(), 0, data.Length, bs, 0, true);

            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

            byte[] result = md5.ComputeHash(bs);

            return System.BitConverter.ToString(result).Replace("-", "").ToLower();

}

Published Saturday, March 19, 2005 8:53 PM by khurram
Filed under:

Comments

No Comments

New Comments to this post are disabled