亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用模數和指數為 Sign In with Apple 創建公共 RSA 密鑰?

如何使用模數和指數為 Sign In with Apple 創建公共 RSA 密鑰?

墨色風雨 2023-05-10 16:55:29
我正在為 IOS 應用程序中使用的 Apple 登錄功能實現服務器端部分。為了驗證 JWT,我需要使用公鑰。我目前停留在如何根據從 Apple 獲得的模數和指數創建公鑰。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

要從指數和模數生成公鑰,需要將它們轉換為 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);


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號