gpt4 book ai didi

c# - 如何在第三方服务器 .net core 上验证 GKLocalPlayer

转载 作者:行者123 更新时间:2023-11-30 18:15:09 24 4
gpt4 key购买 nike

我有以下用于验证 GKLocalPlayer 的代码:

var cert = await GetCertificate(gameCenter.PublicKeyURL);
if (cert.Verify())
{
var rsa = cert.GetRSAPublicKey();
if (rsa != null)
{
var sha256 = new SHA256Managed();
var sig = ConcatSignature(gameCenter.PlayerID, gameCenter.BundleID, gameCenter.TimeStamp, gameCenter.Salt);

var hash = sha256.ComputeHash(sig);
if (rsa.VerifyHash(hash, Convert.FromBase64String(gameCenter.Signature), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1))
{
return true;
}
return false;
}
}

private async Task<X509Certificate2> GetCertificate(string url)
{
var client = new HttpClient();
var response = await client.GetAsync(url);
var rawData = await response.Content.ReadAsByteArrayAsync();
return new X509Certificate2(rawData);
}

private byte[] ConcatSignature(string playerId, string bundleId, string timestamp, string salt)
{
var b = Convert.FromBase64String(salt);

var data = new List<byte>();
data.AddRange(Encoding.UTF8.GetBytes(playerId));
data.AddRange(Encoding.UTF8.GetBytes(bundleId));
data.AddRange(ToBigEndian(Convert.ToUInt64(timestamp)));
data.AddRange(Convert.FromBase64String(salt));
return data.ToArray();
}

private static byte[] ToBigEndian(ulong value)
{
var buffer = new byte[8];
for (int i = 0; i < 8; i++)
{
buffer[7 - i] = unchecked((byte)(value & 0xff));
value = value >> 8;
}
return buffer;
}

但是当我试图验证准确的 GameCenter 时,这总是返回 false。我浏览了所有评论,但找不到专门针对 .net Core 和 GKLocalPlayer 验证发布的内容。

最佳答案

您的代码对我有用。请注意,如果您不在设备上对其进行测试,它将失败(因为数据对时间敏感)

关于c# - 如何在第三方服务器 .net core 上验证 GKLocalPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48947663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com