.NET CORE 3.1 ECDSA生成R,S -Apple Client_secret

发布于 2025-02-07 12:06:37 字数 1302 浏览 2 评论 0原文

我正在遵循本指南 https:>能够通过向Apple发送请求来“服务器验证” Apple AuthCode。

以下这些是生成client_secret的指示:

以下是从SHA-256计算签名的步骤:

  1. 通过使用ECDA签名生成R,S。
  2. 附加R和S,这意味着将R和S一起加在一起。
  3. base64 URL编码附加的结果。

我真的很想找到有关如何完成第一步的任何示例。我以前生成了一个我认为必须签名的字符串,然后以某种方式提取R和s。通过“ ECDSA签名”此字符串,我获得了一个字节数组,但无法真正弄清楚如何通过使用ECDSA签名来解决“生成R,S,或基本上如何获得这些“ R,S”。

任何可以散发出任何光线的人,高度赞赏。

当前示例代码:

public static string GenerateAppleClientSecret(string data)
{
    byte[] bytesData = Encoding.UTF8.GetBytes(data);
    var ecDsa = ECDsaFromFile();

    var signedData = ecDsa.SignData(bytesData, HashAlgorithmName.SHA256);

    string r = "Where do I get r??";
    string s = "Where do I get s??";

    return Base64UrlEncoder.Encode(r + s);
}

public static ECDsa ECDsaFromFile()
{
    var privateKey = LoadPrivateKey().CleanKey(); //loads private Key string (Format -----BEGIN PRIVATE KEY-----) and removes header and footer

    var key = ECDsa.Create();
    key.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _);
    return key;
}

I am following this guide https://p.agnihotry.com/post/validating_sign_in_with_apple_authorization_code to be able to "server verify" an Apple AuthCode by sending a request to Apple.

These below are indications to generate client_secret:

Following are the steps to calculate the signature from the SHA-256:

  1. Generate r,s by signing using ecdsa.
  2. Append r and s, meaning join the r and s together.
  3. base64 url encode the appended result.

I am really struggling to find any examples on how to complete the first step. I previously generated a string that I assume I have to sign, and then somehow extract r and s. By "ecdsa signing" this string, I obtain a byte array, but cant really figure out how to solve the "Generate r,s by signing using ecdsa" piece, or how to basically obtain these "r,s".

Anybody that can shed any light, highly appreciated.

Current Sample code:

public static string GenerateAppleClientSecret(string data)
{
    byte[] bytesData = Encoding.UTF8.GetBytes(data);
    var ecDsa = ECDsaFromFile();

    var signedData = ecDsa.SignData(bytesData, HashAlgorithmName.SHA256);

    string r = "Where do I get r??";
    string s = "Where do I get s??";

    return Base64UrlEncoder.Encode(r + s);
}

public static ECDsa ECDsaFromFile()
{
    var privateKey = LoadPrivateKey().CleanKey(); //loads private Key string (Format -----BEGIN PRIVATE KEY-----) and removes header and footer

    var key = ECDsa.Create();
    key.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _);
    return key;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文