我正在為 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);
添加回答
舉報
0/150
提交
取消