Read public and private EC keys from PEM files

Issue #93 closed
Ati Ranzuglia created an issue

Hi there,

I'm designing an auth server using JWT (JWS and JWE) with OAuth2 in Java. During the prototyping stage, I'm using EcKeyUtil to load a public key from a PEM file.

Is there currently a way to load a private key from a PEM file?

Files have been generated with the following openssl commands (based on JWT Handbook from Auth0):

openssl ecparam -name prime256v1 -genkey -noout -out ecdsa_priv_key.pem
openssl ec -in ecdsa_priv_key.pem -pubout -out ecdsa_pub_key.pem

I'm trying to avoid adding BouncyCastle as a dependency.

Regards

Comments (4)

  1. Brian Campbell repo owner

    There's not currently anything in this lib for PEM private keys. I don't know off hand about regular java APIs for it.

    You could consider generating the key pair in your app (assuming it is doing the signing) and distributing the public key to the verifiers. JWK is kinda nice for that kind of thing. A comment in https://bitbucket.org/b_c/jose4j/issues/34/distributing-keys shows some working with the API for JWKs. You could also use EcKeyUtil to get a PEM encoding of the public key.

  2. Ati Ranzuglia reporter

    Thanks @b_c, unfortunately I surrendered to BouncyCastle ... only to load the private key. We prefer to standardise PEM as the encoding format.

    Thanks for your help!

  3. Log in to comment