read

Here’s a small function to hash a string in C# using the MD5 algorithm.

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

public String md5Hash(String input) {
    String result = "";

    using (MD5 md5 = new MD5CryptoServiceProvider()) {
        result = BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.Default.GetBytes(input)));
    }

    return result.Replace("-", String.Empty);
}

Note that the Replace() at the end is optional and you may remove it should you want the dashes in your hash string.

Happy coding!

Blog Logo

Adam Presley


Published

Image

Adam.Blog()

Adam Presley's blog

Back to Overview