Hashing a string with Sha256

前端 未结 7 2085
一向
一向 2020-12-02 04:31

I try to hash a string using SHA256, I\'m using the following code:

using System;
using System.Security.Cryptography;
using System.Text;
 public class Hash
          


        
7条回答
  •  暖寄归人
    2020-12-02 04:51

    The shortest and fastest way ever. Only 1 line!

    public static string StringSha256Hash(string text) =>
        string.IsNullOrEmpty(text) ? string.Empty : BitConverter.ToString(new System.Security.Cryptography.SHA256Managed().ComputeHash(System.Text.Encoding.UTF8.GetBytes(text))).Replace("-", string.Empty);
    

提交回复
热议问题