Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use json privatekey #235

Closed
lovearthhome opened this issue May 12, 2018 · 16 comments
Closed

How to use json privatekey #235

lovearthhome opened this issue May 12, 2018 · 16 comments
Assignees
Labels

Comments

@lovearthhome
Copy link

lovearthhome commented May 12, 2018

my private key is in such a format, which cannot tobe read by keychain->getPriateKey(*)

how to deal with this private key

{"kty":"RSA","kid":"88483727556929xxxxxxxx9904351185815489","alg":"ES256","n":"ie0IKvKLd7Y3izHcZemdDsVVXg5QtWtGF7XEkILnn66R2\_3a30DikqV409OVL7Hv0ElACgCaBLEgZeGHTcdLE1xxDTna8MMBnBNuMVghvFERCKh8uzpxlQsfcnFd5IFdJWj1x5Tscetrow6lA3h5zYx0rF5TkZzC4DclxgDmITRam0dsHBxr3uk9m9YYBz2mX0ehjY0xxxxlaA4P9OFAO4au9-zcVQop9vLirxdwDedk2p-F9GP6UiQC9V2LTWqkVw\_oPBf9Rlh8Qdi19jA8SeCfzAxJZYlbOTK8dYAFAVEFsvXCFvdaxQefwWFw","e":"AQAB"}

@lovearthhome
Copy link
Author

is there any way to put the privatekey json as php constant?

_20180512174442

@lcobucci
Copy link
Owner

@lovearthhome you're trying to use a JWK, which currently not supported #32. So for now, if you want to use this lib, you'd need to convert the JWK into private/public keys. There're other libraries that support it.

@Spomky
Copy link
Contributor

Spomky commented May 14, 2018

Hi,

No need for another library, you can use that application (PHAR format).

# Download the application
curl -OL https://github.com/web-token/jwt-app/raw/gh-pages/jose.phar
curl -OL https://github.com/web-token/jwt-app/raw/gh-pages/jose.phar.pubkey

# Convert your key
php jose.phar key:convert:pkcs1 '<YOUR JWK HERE>' > your.key

@lovearthhome
Copy link
Author

lovearthhome commented May 15, 2018

@lcobucci @Spomky
thankyou for your answers, the jwk->pem solved. however, go further, error happens!

when use ECDSA, Error happens as follows:

PHP Fatal error: Uncaught Error: Class 'Mdanter\Ecc\EccFactory' not found in jwt_lcobucci/jwt/vendor/lcobucci/jwt/src/Signer/Ecdsa.php:48

_20180515162129

@Ocramius
Copy link
Sponsor Collaborator

For that you will need

"mdanter/ecc": "Required to use Elliptic Curves based algorithms."

@lovearthhome
Copy link
Author

@Ocramius
use composer require mdanter/ecc and then move the files to where?

@Ocramius
Copy link
Sponsor Collaborator

@lovearthhome no need to move anything

@lovearthhome
Copy link
Author

lovearthhome commented May 15, 2018

is this right?
[u1@EevX vendor]$ ls autoload.php composer fgrosse lcobucci mdanter

@Ocramius
Copy link
Sponsor Collaborator

Yeap, that should be it 👍

@lovearthhome
Copy link
Author

lovearthhome commented May 15, 2018

Error happens on:
@Ocramius

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct() must be an instance of Mdanter\Ecc\Math\MathAdapterInterface, instance of Mdanter\Ecc\Math\GmpMath given, called in /jwt_lcobucci/jwt/vendor/lcobucci/jwt/src/Signer/Ecdsa.php on line 50 and defined in /var/www/html/agi.xdua.com/jwt_lcobucci/jwt/vendor/lcobucci/jwt/src/Signer/Ecdsa/KeyParser.php:43 Stack trace: #0 /jwt_lcobucci/jwt/vendor/lcobucci/jwt/src/Signer/Ecdsa.php(50): Lcobucci\JWT\Signer\Ecdsa\KeyParser->__construct(Object(Mdanter\Ecc\Math\GmpMath)) #1 /jwt_lcobucci/test_jwt2.php(9): Lcobucci\JWT\Signer\Ecdsa->__construct() #2 {main} thrown in /jwt_lcobucci/jwt/vendor/lcobucci/jwt/src/Signer/Ecdsa/KeyParser.php on line 43

@Ocramius
Copy link
Sponsor Collaborator

Hmm... @lcobucci do yo remember which version of mdanter/ecc was needed?

Btw, we should probably get rid of the optional dependency, even if it removes Ecdsa support.

@Spomky
Copy link
Contributor

Spomky commented May 15, 2018

Hi @lovearthhome,

As explained in the issue to opened (see web-token/jwt-framework#122), the problem is that you are using an RSA key with an EC algorithm

"kty":"RSA" with "alg":"ES256" are incompatible.

If you want to use your RSA key, then you have to use a RSA based algorithm (RSxxx or PSxxx).
If you absolutely need to use the ES256 algorithm, then you have to use an EC key on the P-256 curve.

@lcobucci
Copy link
Owner

lcobucci commented Jun 24, 2018

@Ocramius once you review #247 I can port it back to v3.3.x and then we'll get rid of it 🎉

@Ocramius
Copy link
Sponsor Collaborator

Reviewed

@lcobucci
Copy link
Owner

lcobucci commented Feb 5, 2019

#288 just backported PHP 7.1-7.3 support, can you please change your requirements to 3.3.x-dev and check if things are working fine for you? Important: this is still a development version and shouldn't be used in production yet.

@lcobucci
Copy link
Owner

Stable v3.3.x has already been released and we can safely close this.

@lcobucci lcobucci self-assigned this Oct 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants