我正在实现 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/