I want to save with JOSE4J the JSON representation of a RsaJsonWebKey object in JSON format and then recreate a RsaJsonWebKey object from it again. I have the marshalling part:
RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
String jwkjson = rsaJsonWebKey.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
but how to unmarshall it and recreate RsaJsonWebKey. That is where I'm stuck as I don't see a constructor of RsaJsonWebKey allowing that.
The question is related to this question
JWT becomes invalid after restarting the server
but it doesn't explain how to unmarshall.
答案 0 :(得分:2)
JWT becomes invalid after restarting the server中示例的下半部分显示了如何从JSON字符串获取JsonWebKey / PublicJsonWebKey对象。使用PublicJsonWebKey publicJsonWebKey = PublicJsonWebKey.Factory.newPublicJwk(jwkJson);
将进行解析/解组,如果需要,可以转换为RsaJsonWebKey
。