usingSystem;usingSystem.Security.Cryptography;usingSystem.Text;namespaceMD5Sample{classProgram{staticvoidMain(string[]args){stringsource="Hello World!";using(MD5md5Hash=MD5.Create()){stringhash=GetMd5Hash(md5Hash,source);Console.WriteLine("The MD5 hash of "+source+" is: "+hash+".");Console.WriteLine("Verifying the hash...");if(VerifyMd5Hash(md5Hash,source,hash)){Console.WriteLine("The hashes are the same.");}else{Console.WriteLine("The hashes are not same.");}}}staticstringGetMd5Hash(MD5md5Hash,stringinput){// 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.StringBuildersBuilder=newStringBuilder();// Loop through each byte of the hashed data// and format each one as a hexadecimal string.for(inti=0;i<data.Length;i++){sBuilder.Append(data[i].ToString("x2"));}// Return the hexadecimal string.returnsBuilder.ToString();}// Verify a hash against a string.staticboolVerifyMd5Hash(MD5md5Hash,stringinput,stringhash){// Hash the input.stringhashOfInput=GetMd5Hash(md5Hash,input);// Create a StringComparer an compare the hashes.StringComparercomparer=StringComparer.OrdinalIgnoreCase;if(0==comparer.Compare(hashOfInput,hash)){returntrue;}else{returnfalse;}}}}