Created
September 15, 2017 13:42
-
-
Save DCCoder90/be6e8f2d09f266054640f9e56dff7306 to your computer and use it in GitHub Desktop.
Create MD5 hash from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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