Created
October 22, 2018 21:57
-
-
Save icebeam7/657fc28ada45d0a6dcc3617eab67171f to your computer and use it in GitHub Desktop.
MyStore.Services: MD5Security.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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