Extracting private key for jwt library from jwks

Hi Nacha,
You can use the java security classes to build a java Private key using the n and d parameters of the jwk:
RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(
new BigInteger(1, Base64.getUrlDecoder().decode(/* keyModulus, n */)),
new BigInteger(1, Base64.getUrlDecoder().decode(/* privateExponent, d */)
);
KeyFactory factory = KeyFactory.getInstance(“RSA”);
PrivateKey privateKey = factory.generatePrivate(rsaPrivateKeySpec);

https://docs.oracle.com/javase/8/docs/api/java/security/spec/RSAPrivateKeySpec.html
https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html
https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
https://docs.oracle.com/javase/8/docs/api/java/security/KeyFactory.html

1 Like