Creating RsaJsonWebKey with RSAPrivateKey

Issue #50 new
Former user created an issue

First, Thanks for the great library! it really helps allot.

now the actual problem is that I'd like to use the JwksDecryptionKeyResolver with private rsa keys. I see that the RsaJsonWebKey does not have a constructor from such object, it only has one from a map containing the various used numbers. For me that makes the library a bit cumbersome to use...

Thanks!

Comments (2)

  1. Brian Campbell repo owner

    Try something like the below. Typically using the Factory on PublicJsonWebKey or JsonWebKey is the way to get a JsonWebKey instance. And you need the public part in JWK so that's what you give to the factory's method. Then use the setPrivateKey(...) to provide the object with the private key.

            RSAPrivateKey rsaPrivateKey  = ...
            RSAPublicKey rsaPublicKey =...
    
            PublicJsonWebKey publicJsonWebKey = PublicJsonWebKey.Factory.newPublicJwk(rsaPublicKey);
            publicJsonWebKey.setPrivateKey(rsaPrivateKey);
    
            publicJsonWebKey.setKeyId("might need this...");
            publicJsonWebKey.setCertificateChain(......);  // or this 
    
  2. Log in to comment