Skip to content

Instantly share code, notes, and snippets.

@schweigert
Created July 7, 2017 15:23
Show Gist options
  • Select an option

  • Save schweigert/f56319b10f9659b537cc8d338995e75c to your computer and use it in GitHub Desktop.

Select an option

Save schweigert/f56319b10f9659b537cc8d338995e75c to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Security.Cryptography;
namespace MD5test
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine(MD5Hash("Hello World!"));
}
public static string MD5Hash(string input)
{
// hash the string
MD5 md5 = MD5.Create();
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// convert to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment