Skip to content

Instantly share code, notes, and snippets.

@PurwantoGZ
Created April 11, 2017 05:01
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 PurwantoGZ/82f500b5913f9db435a1d768b21e9278 to your computer and use it in GitHub Desktop.
Save PurwantoGZ/82f500b5913f9db435a1d768b21e9278 to your computer and use it in GitHub Desktop.
Hash String MD5 using C#
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;
}
@PurwantoGZ
Copy link
Author

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"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment