using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; namespace SAL_OUTSTOCK.Utils { internal static class SHA256Helper { /// /// SHA256加密 /// /// /// public static string SHA256EncryptString(string data) { byte[] bytes = Encoding.UTF8.GetBytes(data); byte[] hash = SHA256Managed.Create().ComputeHash(bytes); StringBuilder builder = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { builder.Append(hash[i].ToString("x2")); } return builder.ToString(); } /// /// SHA256加密 /// /// 待加密字符串 /// 加密数组 public static Byte[] SHA256EncryptByte(string StrIn) { var sha256 = new SHA256Managed(); var Asc = new ASCIIEncoding(); var tmpByte = Asc.GetBytes(StrIn); var EncryptBytes = sha256.ComputeHash(tmpByte); sha256.Clear(); return EncryptBytes; } } }