簡體   English   中英

如何使用模數和指數為 Apple 登錄創建公共 RSA 密鑰?

[英]How to create public RSA key using modulus and exponent for Sign In with Apple?

我正在為在 IOS 應用程序中使用的 Apple 功能實現登錄的服務器端部分。

為了驗證 JWT,我需要使用公鑰。 我現在卡住了如何從我從 Apple 獲得的模數和指數創建公鑰。

要從指數和模數生成公鑰,需要將它們轉換為 BigInteger,然后可以使用 Java security 中的 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM