invalidKeySpecException error "not in PKCS8 format"
Encrypted JWT token parsing I am trying to use nimbus-jose-jwt-2.25.jar. but here I got blocked on loading the private key ,which is reading as external file (.pem/.key format) . Code Snippet: byte [] encoded = Base64.decodeBase64(pemBytes); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey pk = kf.generatePrivate(keySpec); <- error loading private key has been failed on invalidKeySpecException error not in PKCS8 format.
I have tried to downgrading the code nimbus-jose-jwt--2.15.1 as mentioned here "http://social.msdn.microsoft.com/Forums/en-US/951f090d-6013-4d76-88a9-67e13fabaa83/padding-error-while-decrypt-jwt-sso-token-with-josejwt?forum=xboxoneappswithhtml5"
but unfortunately no luck could you help me on this issue.
Thanks,in advance.
Comments (4)
-
-
The MSDN link appears to be broken?
-
reporter Hi Vladimir, Thanks for your reply. Yes your assumption is correct this was the issue and luckily I could identify and resolved resolved the issue.
Best Limson km
-
- changed status to resolved
Glad to hear that! I'm closing the ticket :)
- Log in to comment
Hi,
Could it be that the "-----BEGIN RSA PRIVATE KEY-----" and "-----END RSA PRIVATE KEY-----" delimiters are still there? ;)
If that's the case, the following answer can be of help:
http://stackoverflow.com/questions/7216969/getting-rsa-private-key-from-pem-base64-encoded-private-key-file
Please, let me know if that was the issue.