Unable to Parse RSA Public Key in PEM Format

Issue #452 resolved
Ryan Daniels created an issue

Doing my best to piece together a proper setup for BC with Nimbus, I followed instructions on the following pages:

https://connect2id.com/products/nimbus-jose-jwt/examples/pem-encoded-objects

https://connect2id.com/products/nimbus-jose-jwt/jca-algorithm-support

https://bitbucket.org/connect2id/nimbus-jose-jwt/issues/309/didnt-find-class

But, despite seemingly having everything set up property, I could not get Nimbus to parse an RSA public key in PEM format.

Dependencies:

com.nimbusds:nimbus-jose-jwt:9.15.2
org.bouncycastle:bcprov-jdk15on:1.69
org.bouncycastle:bcpkix-jdk15on:1.69

Data format:

-----BEGIN RSA PUBLIC KEY-----
(redacted)
-----END RSA PUBLIC KEY-----

Parse code:

JWK.parseFromPEMEncodedObjects(rsaPemString);

Error:

problem extracting key: java.lang.IllegalArgumentException: illegal object in getInstance: org.bouncycastle.asn1.DLSequence
com.nimbusds.jose.JOSEException: problem extracting key: java.lang.IllegalArgumentException: illegal object in getInstance: org.bouncycastle.asn1.DLSequence
at app//com.nimbusds.jose.jwk.PEMEncodedKeyParser.parseKeys(PEMEncodedKeyParser.java:108)
at app//com.nimbusds.jose.jwk.JWK.parseFromPEMEncodedObjects(JWK.java:764)

Also, tried adding this, but it did not make a difference:

Security.addProvider(BouncyCastleProviderSingleton.getInstance());

Comments (1)

  1. Vladimir Dzhuvinov

    The error message suggests there is an expected object (sequence of some data) in the raw binary data, and this causes the parse method to fail.

  2. Log in to comment