How to Compute MD5 Hash using C#

CSharp · Console

/Program.cs

using System;
using System.Text;
using System.Security.Cryptography;

public class Program
{
	public static void Main()
	{
		StringBuilder hash = new StringBuilder();
		
		// input string
		string input = "Technology crowds";
		
		// defining MD5 object
		var md5provider = new MD5CryptoServiceProvider();
		// computing MD5 hash
		byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input));
		for (int i = 0; i < bytes.Length; i++)
		{
			hash.Append(bytes[i].ToString("x2"));
		}
		
		// final output
		Console.WriteLine(string.Format("The MD5 hash is: {0}",hash));
	}
}
;