Hi Colm,

thank you for you answer!
I ended up doing this [1], in order to also return the modulus and the private key. I don't know whether it could be accomplish in a better way, maybe by taking more advantage from the "JwkUtils" class!

Thank you for your help!
Best regards,
Matteo

[1] https://gist.github.com/mat-ale/b2a8eb20b45b980f411ff068114ba6c1


On 2020/04/21 13:41:01, Colm O hEigeartaigh <cohei...@apache.org> wrote:
> Hi Matteo,
>
> You could use the standard way of generating Random keys in Java and
> combine it with the CXF API to write out the json equivalent. For example:
>
> KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
> kpg.initialize(2048);
> KeyPair keyPair = kpg.generateKeyPair();
>
> JsonWebKey jsonWebKey =
> JwkUtils.fromRSAPublicKey(((RSAPublicKey)keyPair.getPublic()),
> (String)null);
> JwkReaderWriter writer = new JwkReaderWriter();
> String json = writer.jwkToJson(jsonWebKey);
> System.out.println("JSON: " + json);
>
> Colm.
>
>
> On Tue, Apr 21, 2020 at 9:02 AM Matteo Alessandroni <skylar...@apache.org>
> wrote:
>
> > Hi,
> >
> > is it possible to have a snippet on how to generate random JWK keys
> > (e.g. the JSON on [1])?
> >
> > I was checking the official reference on [2], but could not figure out
> > how to do that.
> >
> > Thanks
> >
> > [1]
> >
> > https://raw.githubusercontent.com/apache/cxf/master/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt
> > [2] https://cxf.apache.org/docs/jax-rs-jose.html#JAX-RSJOSE-JWKKeys
> >
>

Reply via email to