Hash string using MD5 C# .Net 8
Hash using MD5 C# .Net code
public static string Hash_UsingMD5(IDictionary<string, string> stringADict, string partnerKey, out string errMsg)
{
var sign = "";
errMsg = string.Empty;
try
{
stringADict.Remove("sign");
stringADict.Remove("signature");
StringBuilder builder = new();
foreach (var item in stringADict.Select(t => t).OrderBy(t => t.Key))
{
builder.Append($"{item.Key}={item.Value}&");
}
if (!string.IsNullOrEmpty(partnerKey))
{
builder.Append($"key={partnerKey}");
}
var stringSignTemp = builder.ToString().TrimEnd('&');
sign = MD5Encrypt(stringSignTemp, "UTF-8").ToUpper();
}
catch (Exception ex)
{
errMsg = ex.Message;
}
return sign;
}