java - 如何使用模数和指数创建 RSA 公钥以用于 Sign In with Apple?

标签 java jwt apple-sign-in

我正在实现 IOS 应用程序中使用的“使用 Apple 登录”功能的服务器端部分。

为了验证 JWT,我需要使用公钥。我现在陷入了如何根据从苹果获得的模数和指数创建公钥的问题。

最佳答案

要从指数和模数生成公钥,需要将它们转换为BigInteger,然后可以使用Java安全性中的KeyFactory。

例如:


  String modulus = "modulus from Apple";
  String exponent = "exponent from Apple";
  byte[] modulusByte = Base64.getUrlDecoder().decode(modulus);

  BigInteger modulusAsBigInt = new BigInteger(1, modulusByte);
  byte[] exponentByte = Base64.getUrlDecoder().decode(exponent);
  BigInteger exponentAsBigInt = new BigInteger(1, exponentByte);

  RSAPublicKeySpec spec = new RSAPublicKeySpec(modulusAsBigInt, exponentAsBigInt);
  KeyFactory factory = KeyFactory.getInstance("RSA");
  PublicKey pub = factory.generatePublic(spec);

关于java - 如何使用模数和指数创建 RSA 公钥以用于 Sign In with Apple?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57329655/

相关文章:

java - 在 JFrame 中显示图像

Angular 5 HTTP Client 的 Response header 中缺少 "Authorization"

ruby-on-rails - 使用 rails RPUSH gem 为 APNS 编码 JWT key

ios - 如何在通过身份验证后退出 Apple

javascript - 如何在 Apple JS 中使用 "Sign In with Apple"

java - 如何在谷歌地图静态 API 中的标记上显示标签(字符串)?

java - 无法在 Linux 中运行简单的 bash 命令,权限被拒绝

java - 无法在字符串列表中搜索 - Objectify 3.1

reactjs - 如何从回调发送 JWT 到 React 客户端?

ios - 使用 Apple ID 登录显示响应类型无效