Hash using SHA 512 C# .Net 8

Hash using SHA 512 C# .Net 8 Code


/// 
/// hash using SHA512
/// 
///
///
/// 
public static string Hash_SHA512(Dictionary<string, string> keyValues, string secret)
{
    keyValues.Remove("sign");
    StringBuilder builder = new();
    foreach (var item in keyValues.Select(t => t).OrderBy(t => t.Key))
    {
        if (new List { "customer_email", "customer_phone", "return_url" }.Contains(item.Key))
        {
            builder.Append($"{item.Key}={Uri.EscapeDataString(item.Value)}&");
        }
        else
        {
            builder.Append($"{item.Key}={item.Value}&");
        }
    }
    using SHA512 sha521Hash = SHA512.Create();
    //From String to byte array
    byte[] sourceBytes = Encoding.UTF8.GetBytes(builder.ToString().TrimEnd('&') + secret);
    byte[] hashBytes = sha521Hash.ComputeHash(sourceBytes);
    string hash = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
return hash.ToLower(); }

Summary: