java-jwt
java-jwt copied to clipboard
Unable to construct Public key
I am unable to construct the Public key from .pem file. I need public key to verify the JWT token. Here is how i am trying.

Downloaded the .pem file from link - https://{instance}.auth0.com/dbconnections/pem
And the error i am getting,
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: ObjectIdentifier() – data isn’t an object ID (tag = -96)
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:205)
at java.security.KeyFactory.generatePublic(KeyFactory.java:334)
at com.ceino.supportapp.test.JWTClass.getPublicKey(JWTClass.java:93)
at com.ceino.supportapp.test.JWTClass.readPublicKeyFromFile(JWTClass.java:106)
at com.ceino.supportapp.test.JWTClass.main(JWTClass.java:35)
Caused by: java.security.InvalidKeyException: IOException: ObjectIdentifier() – data isn’t an object ID (tag = -96)
at sun.security.x509.X509Key.decode(X509Key.java:397)
at sun.security.x509.X509Key.decode(X509Key.java:402)
at sun.security.rsa.RSAPublicKeyImpl.(RSAPublicKeyImpl.java:86)
at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:298)
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:201)
… 4 more
Creating new or reading existing keys is not part of this library's responsibilities. I saw Ashish replied to you on the community suggesting the use of jwks-rsa-java for fetching the public keys. Have you tried that?
https://community.auth0.com/t/verify-jwt-token-received-from-auth0/35581/4.