Sunday, July 8, 2012

MD5 In c# - Convert to string into MD5

using System.Security.Cryptography;

private string GetMd5Hash(MD5 md5Hash, string input)
        {

            // Convert the input string to a byte array and //compute the hash.
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }

No comments:

Post a Comment