JOSE4J:如何从 RsaJsonWebKey 的 JSON 表示创建 RsaJsonWebKey 对象

JOSE4J: How to create a RsaJsonWebKey object from a JSON representation of RsaJsonWebKey

我想用 JOSE4J 以 JSON 格式保存 RsaJsonWebKey 对象的 JSON 表示,然后再次从中重新创建 RsaJsonWebKey 对象。我有编组部分:

RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);

字符串 jwkjson = rsaJsonWebKey.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);

但是如何解组它并重新创建 RsaJsonWebKey。这就是我卡住的地方,因为我没有看到 RsaJsonWebKey 的构造函数允许这样做。

问题与此问题相关

JWT becomes invalid after restarting the server

但它没有解释如何解组。

JWT becomes invalid after restarting the server 中示例的下半部分确实展示了如何从 JSON 字符串获取 JsonWebKey/PublicJsonWebKey 对象。使用 PublicJsonWebKey publicJsonWebKey = PublicJsonWebKey.Factory.newPublicJwk(jwkJson); 将执行 parsing/unmarshalling,如果需要可以转换为 RsaJsonWebKey