Skip to content

Instantly share code, notes, and snippets.

@lamngockhuong
Last active December 29, 2017 09:49
Show Gist options
  • Save lamngockhuong/fd9631852dbc4af3ae48 to your computer and use it in GitHub Desktop.
Save lamngockhuong/fd9631852dbc4af3ae48 to your computer and use it in GitHub Desktop.
[MD5 Hash Method In C# (using for password)] #csharp
public static String MD5Hash(String source)
{
MD5 md5 = new MD5CryptoServiceProvider();
// compute hash from the bytes of text
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(source));
// get hash result after compute it
byte[] result = md5.Hash;
StringBuilder text = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
// change it into 2 hexadecimal digits
// for each byte
text.Append(result[i].ToString("x2"));
}
return text.ToString();
}
-------------------------
Lam Ngoc Khuong
http://ngockhuong.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment