计算SHA1摘要
huster-songtao opened this issue · comments
Tao Song commented
/// <summary>
/// 计算SHA1摘要
/// </summary>
/// <param name="str">字符串</param>
/// <param name="encoding">编码</param>
/// <returns></returns>
public static byte[] ToSha1Bytes(this string str, Encoding encoding)
{
#pragma warning disable CS0618
SHA1 sha1 = new SHA1CryptoServiceProvider();
#pragma warning restore CS0618
byte[] inputBytes = encoding.GetBytes(str);
byte[] outputBytes = sha1.ComputeHash(inputBytes);
return outputBytes;
}
可以修改为:
/// <summary>
/// 计算SHA1摘要
/// </summary>
/// <param name="str">字符串</param>
/// <param name="encoding">编码</param>
/// <returns>返回SHA1摘要</returns>
public static byte[] ToSha1Bytes(this string str, Encoding encoding)
{
using var sha1 = SHA1.Create();
byte[] inputBytes = encoding.GetBytes(str);
return sha1.ComputeHash(inputBytes);
}
其实我应该给你pr的...不过提交pr改了的比较多,怕乱了版本
apevolo commented
@huster-songtao 感谢你的提议,代码已优化