SHA256Managed/SHA512Managed已过时:Derived cryptographic types are obsolete. Use the Create method on the base type instead
解决方案
C# 全选
/// <summary>
/// 散列算法加密SHA256位Hash,不可逆
/// </summary>
/// <param name="clearText">明文字符串</param>
/// <returns></returns>
public static string ToSHA256Hash(string clearText)
{
SHA256 sha256 = SHA256.Create();
byte[] encryptedBytes = sha256.ComputeHash(UTF8Encoding.UTF8.GetBytes(clearText));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encryptedBytes.Length; i++)
{
sb.AppendFormat("{0:x2}", encryptedBytes[i]);
}
return sb.ToString();
}
C# 全选
/// <summary>
/// 散列算法加密SHA512位Hash,不可逆
/// </summary>
/// <param name="clearText">明文字符串</param>
/// <returns></returns>
public static string ToSHA512Hash(string clearText)
{
SHA512 shaM = SHA512.Create();
byte[] encryptedBytes = shaM.ComputeHash(UTF8Encoding.UTF8.GetBytes(clearText));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encryptedBytes.Length; i++)
{
sb.AppendFormat("{0:x2}", encryptedBytes[i]);
}
return sb.ToString();
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网