Created
April 11, 2017 05:01
-
-
Save PurwantoGZ/82f500b5913f9db435a1d768b21e9278 to your computer and use it in GitHub Desktop.
Hash String MD5 using C#
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
private string GetMD5Hash(string input) | |
{ | |
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); | |
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input); | |
byte[] hash = md5.ComputeHash(inputBytes); | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0; i < hash.Length; i++) | |
{ | |
sb.Append(hash[i].ToString("x2")); | |
} | |
return sb.ToString(); | |
} | |
private bool VerifyMd5Hash(string input, string hash) | |
{ | |
string hashOfInput = GetMD5Hash(input); | |
StringComparer comparer = StringComparer.OrdinalIgnoreCase; | |
return (0 == comparer.Compare(hashOfInput, hash)) ? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
untuk merubah hasilnya menjadi Upper Case tinggal dirubah di baris 9 sb.Append(hash[i].ToString("x2")); dirubah menjadi sb.Append(hash[i].ToString("X2"));