Skip to content

Instantly share code, notes, and snippets.

@pisceanfoot
Created May 14, 2014 01:17
Show Gist options
  • Save pisceanfoot/67970cb42b697d0fc18d to your computer and use it in GitHub Desktop.
Save pisceanfoot/67970cb42b697d0fc18d to your computer and use it in GitHub Desktop.
EnCryptographyHelper with md5
public static class EnCryptographyHelper
{
public static string MD5Encoding(byte[] content)
{
MD5 md5 = MD5.Create();
byte[] bytes = md5.ComputeHash(content);
return HexToString(bytes);
}
public static string MD5Encoding(string content, Encoding encoding)
{
MD5 md5 = MD5.Create();
byte[] bytes = md5.ComputeHash(encoding.GetBytes(content));
return HexToString(bytes);
}
public static string HexToString(byte[] buffer)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < buffer.Length; i++)
{
result.Append(buffer[i].ToString("X2"));
}
return result.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment