为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用模数和指数为 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 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信