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;
This website is making use of cookies for website analysis. Data is collected anonymously and solely for the purpose of improving the website. Do you agree to the use of cross-session cookies?