HashUtil.cs 491 B

123456789101112131415161718
  1. using System.Linq;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4. namespace WebAPIBase.Utils
  5. {
  6. public static class HashUtil
  7. {
  8. public static string GetSha256FromString(string strData)
  9. {
  10. var message = Encoding.ASCII.GetBytes(strData);
  11. var hashString = new SHA256Managed();
  12. var hashValue = hashString.ComputeHash(message);
  13. return hashValue.Aggregate("", (current, x) => current + $"{x:x2}");
  14. }
  15. }
  16. }