0

I want to sign JWT token from a local jwk file containing keys in JWKSet. I'm trying to achieve this by loading json file in JWTSet object and then sign the token with it but it through an exception that signer need to have private key. Is there a way to sign jwt from JWKSet? Here is the code snippet:

import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.JWSSigner;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import com.nimbusds.jose.crypto.RSASSASigner;

public class testJWK {
    public static void main(String[] args) throws IOException, ParseException {
    
        JWKSet jwks = JWKSet.load(new File("./jwkset.json"));

        JWSSigner signer = new RSASSASigner(jwks);
    }
}
  • *exception that signer need to have private key* - that's right, for signing you need a private key. When the JWK only contains public keys, then you can't sign with it. – jps Aug 19 '20 at 19:58
  • `signer` has JWK set, i.e., it contains public and private key set. – Babru bhan Aug 21 '20 at 07:55
  • @Babrubhan Have you found the solution for this issue? – SKK Jun 12 '21 at 15:42

0 Answers0