24 lines
701 B
C#
24 lines
701 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace FishGameService.Utils
|
|
{
|
|
public static class SignHelper
|
|
{
|
|
public static string Sign(string rawStr, string signKey)
|
|
{
|
|
var input = rawStr + "|" + signKey;
|
|
var hash = MD5.HashData(Encoding.UTF8.GetBytes(input));
|
|
return Convert.ToHexString(hash).Substring(0, 8).ToLower();
|
|
}
|
|
|
|
public static bool Verify(string rawStr, string signKey, string expectedSign)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(expectedSign))
|
|
return false;
|
|
var computed = Sign(rawStr, signKey);
|
|
return computed == expectedSign;
|
|
}
|
|
}
|
|
}
|