Support construct of ECKey (or PrivateKey) from PEM with only private key

Issue #322 new
Former user created an issue

https://stackoverflow.com/questions/57423015/does-nimbus-jose-support-construct-of-eckey-given-only-a-private-key

Trying to implement the Apple Sign-in flow, and from what I can tell there is no way to do this with the public apis. The closest I've gotten is this:

    val pemContents = keyFile?.url?.readText()
    val jwk = ECKey.parseFromPEMEncodedObjects(pemContents)
    val signer = ECDSASigner(jwk as ECKey)
    ...

Which blows up with NPE because the pem apple gives only contains the private key. Looking at the implementation of parseFromPEMEncodedObjects it appears it would be trivial to create a method like

ECKey.parsePrivateKeyFromPEMEncodedObjects(pemContents)

since the private key is present and ECDSASigner supports construction from private key only.

I also tried extracting the minimal code needed to implement that operation in my application code but there are at least 2 helper methods that are private in ECKey and then an entire class tree that is package private that those methods rely upon (PEMEncodedKeyParser and its dependencies). Presumably if PEMEncodedKeyParser was exposed as public it would provide an avenue for me to reasonably implement in application code.

Comments (2)

  1. Log in to comment