Creation Of md5 Encryption in C#

Creation Of md5 ENCRYPTION in C# :

Namespace: 

using System.Security.Cryptography;

using System.Text;

 

// The following function converts the string to MD5 hash string

 

public string GetMD5Hash(string input)

{

    using (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. 

 

for (int i = 0; i < (data.Length); i++)

{

   sBuilder.Append(data[i].ToString("x2"));

}

 

// Return the hexadecimal string.

 

return sBuilder.ToString();

}  

// Verify a hash against a string. public bool VerifyMd5Hash(string input, string hash) 

{

// Uses GetMD5Hash function from earlier convert convert input into MD5 

// hash and compare it to hash string

string hasOfInput = GetMD5Hash(input);

StringComparer comparer = StringComparer.OrdinalIgnoreCase

if (0 == comparer.Compare(hasOfInput,hash))

return true;

else

return false;

}