Skip to content

Instantly share code, notes, and snippets.

@xbotter
Created May 11, 2020 05:31
Show Gist options
  • Save xbotter/cc757f4fb5b22f15acc143c859866d76 to your computer and use it in GitHub Desktop.
Save xbotter/cc757f4fb5b22f15acc143c859866d76 to your computer and use it in GitHub Desktop.
C# MD5 String
public static string GetMd5String(string input)
{
using (MD5 md5Hash = MD5.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
}
@xbotter
Copy link
Author

xbotter commented May 11, 2020

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