Hi all,
I created a pub/priv cert pair with:
.\openssl.exe genpkey -algorithm RSA -out ../ca_private.pem -pkeyopt rsa_keygen_bits:2048
.\openssl.exe req -x509 -new -nodes -key ..\ca_private.pem -sha256 -out ..\ca_cert.pem -subj "/CN=unused" -config .\openssl.cnf -days 7300
With those 2 files I'm trying to instantiate a JWT:
import static java.nio.charset.StandardCharsets.ISO_8859_1
JWT jwt = new JWT()
String pubKey = new String( getClass().getResourceAsStream( '/ca_cert.pem' ).bytes, ISO_8859_1 )
String privKey = new String( getClass().getResource( '/ca_private.pem' ).bytes, ISO_8859_1 )
jwt.addJWK new JWK( 'RS256', true, pubKey, privKey )
The code is throwing the exception:
java.lang.RuntimeException: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at io.vertx.ext.jwt.JWK.<init>(JWK.java:139)
.....
Caused by: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
at io.vertx.ext.jwt.JWK.<init>(JWK.java:131)
... 43 more
Caused by: java.security.InvalidKeyException: invalid key format
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:331)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)
What am I missing?