Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created October 22, 2018 21:57
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 icebeam7/657fc28ada45d0a6dcc3617eab67171f to your computer and use it in GitHub Desktop.
Save icebeam7/657fc28ada45d0a6dcc3617eab67171f to your computer and use it in GitHub Desktop.
MyStore.Services: MD5Security.cs
using System.Text;
using System.Linq;
using System.Security.Cryptography;
namespace MyStore.Services
{
public static class MD5Security
{
public static string ToMD5Hash(this string str)
{
if (string.IsNullOrEmpty(str))
return null;
return Encoding.ASCII.GetBytes(str).ToMD5Hash();
}
public static string ToMD5Hash(this byte[] bytes)
{
if (bytes == null || bytes.Length == 0)
return null;
using (var md5 = MD5.Create())
{
return string.Join("", md5.ComputeHash(bytes).Select(x => x.ToString("X2")));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment