Get MD5 Checksum / Hash (C#/CSharp)

The following code snippet demonstrates how to calculate the MD5 checksum of a given input string. The MD5 checksum is returned as a hexadecimal string (as usual). Don't forget to include the System.Security.Cryptography namespace so that the MD5 Crypto Provider is found.

private string MD5(string input)
{
    byte[] inputBytes = System.Text.Encoding.Default.GetBytes(input);

    MD5CryptoServiceProvider myMD5CryptoServiceProvider = new MD5CryptoServiceProvider();
    byte[] hash = myMD5CryptoServiceProvider.ComputeHash(inputBytes);

    string result = "";
    foreach (byte b in hash)
    {
        result += b.ToString("X2");
    }

    return result;
}