简体   繁体   English

如何验证第三方服务器.net核心上的GKLocalPlayer

[英]How to verify GKLocalPlayer on third party server .net core

I have the followinf code for verification of GKLocalPlayer: 我有以下代码用于验证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;
}

but this always returns false, when I am trying to verify the accurate GameCenter. 但是当我试图验证准确的GameCenter时,这总是返回false。 I browsed through all the comments, but I cannot find anything posted specifically for .net Core and GKLocalPlayer verification. 我浏览了所有评论,但我找不到专门针对.net Core和GKLocalPlayer验证发布的内容。

Your code worked for me. 你的代码对我有用。 Note it will fail if you not testing it on a device (as the data is time sensitive) 请注意,如果您未在设备上测试它将会失败(因为数据是时间敏感的)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在.NET Core中将第三方nuget包(依赖项)全局部署到服务器? - How to deploy third party nuget packages (dependencies) globally to the server in .NET Core? 如何在不使用.Net Core 中的第三方记录器的情况下登录文件? - How to log to a file without using third party logger in .Net Core? 如何在.Net Core 中使用不同的第三方记录器登录到文件? 第三方记录器可能会在应用程序启动时动态更改 - How to log to a file using different third party logger in .Net Core? Third party logger may change dynamically when application starts 如何在 asp.net 核心网络应用程序中登录文件 - 没有任何第三方工具 - How to log to a file in asp.net core web app - wtihout any third party tools 如何从MVC 6.0和asp net core应用程序中的第三方rest API获取数据 - How to get data from third party rest API in MVC 6.0 and asp net core application ASP.NET Core Web API - 如何将指定字段作为有效负载传递给第三方 API - ASP.NET Core Web API - How to pass specified fields as payload to third party API 如何在 ASP.NET Core 6 Web API 中从第三方 API 获取数据 - How to fetch data from a third party API in ASP.NET Core 6 Web API ASP.NET核心中第三方数据上下文的依赖注入 - Dependency Injection for third party data context in ASP.NET core 任何第三方.net SDK均可针对任何邮件服务器进行编程 - any third party .net sdk for programming against any mail server 在.net中重命名第三方dll - renaming a third party dll in .net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM