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

时间:2017-06-04 23:49:37

标签: json unmarshalling jose4j

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.

1 个答案:

答案 0 :(得分:2)

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