How to create an RSA JWK from java.security.interfaces.RSAPrivateKey ?

Issue #215 duplicate
Eric Colinet created an issue

Hello,

I’m trying to create a JsonWebKey from an RSAPrivateKey.

Looking at JsonWebKey.Factory.newJwk it seems that I can’t do that with a private key. I have to use a public key.

I don’t understand why it’s not possible because it looks like a common use case, so maybe I miss something.

I managed to achieve what I need like that :

val generator = KeyPairGenerator.getInstance("RSA")
generator.initialize(2048)
val pair = generator.generateKeyPair()

val rsaJwk = JsonWebKey.Factory.newJwk(pair.public) as RsaJsonWebKey
rsaJwk.privateKey = pair.private

It’s weird but it works.

Is there an other way to do that ?

Comments (1)

  1. Log in to comment