1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/// <summary> /// SHA256加密 /// </summary> /// <param name="data"></param> /// <returns></returns> public 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(); } /// <summary> /// SHA256加密 /// </summary> /// <param name="StrIn">待加密字符串</param> /// <returns>加密数组</returns> public 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; } |
from:https://www.cnblogs.com/webttt/p/12762318.html
View Details