.NET Core中使用System.Security.Cryptography.MD5类,找不到请添加NuGet:System.Security.Cryptography.Algorithms

public static string GetMD5(string str)
{
    var md5 = System.Security.Cryptography.MD5.Create();
    byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(str));

    StringBuilder sBuilder = new StringBuilder();

    for (int i = 0; i < data.Length; i++)
    {
        sBuilder.Append(data[i].ToString("x2"));
    }

    return sBuilder.ToString();
}