xianhc / apevolo-api

.Net 8 、SqlSugar ORM、Vue 2.X、RBAC、前后端分离的开箱则用的企业级中后台权限管理系统

Home Page:https://www.apevolo.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

计算SHA1摘要

huster-songtao opened this issue · comments

    /// <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改了的比较多,怕乱了版本

@huster-songtao 感谢你的提议,代码已优化