Skip to content

Instantly share code, notes, and snippets.

@DCCoder90
Created September 15, 2017 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DCCoder90/be6e8f2d09f266054640f9e56dff7306 to your computer and use it in GitHub Desktop.
Save DCCoder90/be6e8f2d09f266054640f9e56dff7306 to your computer and use it in GitHub Desktop.
Create MD5 hash from a string
using System;
using System.Text;
using System.Security.Cryptography;
static public string GetMd5Sum(string str){
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);
StringBuilder sb = new StringBuilder();
for (int i=0;i<result.Length;i++)
{
sb.Append(result[i].ToString("X2"));
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment