Skip to content

Instantly share code, notes, and snippets.

@jaysonrowe
Created September 23, 2012 21:37
Show Gist options
  • Save jaysonrowe/3773128 to your computer and use it in GitHub Desktop.
Save jaysonrowe/3773128 to your computer and use it in GitHub Desktop.
Class to generate MD5 hash of string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace MD5Util
{
public class Encryptor
{
public string MD5Hash(string text)
{
MD5 md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));
byte[] result = md5.Hash;
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
strBuilder.Append(result[i].ToString("x2"));
}
return strBuilder.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment