AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Wednesday 27 April 2016

How to Encrypt string with MD5 hash algorithm in c#?

In this blog post I will discuss How to Encrypt string with MD5 hash in c#? Use below method for converting a string to MD5 hash.

        public static string GetMd5Hash(string input)
            MD5 md5Hash = MD5.Create();
            // 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. 
            int i = 0;
            for (i = 0; i <= data.Length - 1; i++)
            // Return the hexadecimal string. 
            return sBuilder.ToString();

It's quite simple & easy to convert MD5 hash.

Example : 
string str = "";

Output: 38a7066d8c26659b8c6e32f3f2fddc5f


Post a Comment

  • Popular Posts
  • Comments