-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Error using RS256 - openssl_sign(): supplied key param cannot be coerced into a private key #98
Comments
@myuseringithub couldn't work for me :( |
@parthjdabhi You are probably missing something out, ya hard to debug sometimes, just check carefully. and check the solution in the provided link. |
@myuseringithub are you using RS256? I only get it to work with HS256 I have setup everything, service email, key etc And what function is |
Do you try using double quote instead of single quote ? I managed to solve it with double quote. I mean, if you write $token = JWT::encode($payload, "YourGiantKey", 'RS256'); instead of $token = JWT::encode($payload, 'YourGiantKey', 'RS256'); I dont know how to solve the problem with the var $key by the way. If you manage to do it, please let me know :) |
I ran into this issue and resolved it by changing how I was generating the key pairs. I'm not using google cloud compute for any of this. If you're using ssh-keygen to give you your key pairs, try openssl instead.
Where .pem is your private key and .pub is your public one. I realize this probably comes down to not providing the proper arguments to ssh-keygen, but this was an easier solution for me. |
WTF |
The reason is because the key contains new-line characters ( |
On a similar note; if your RSA Private Key has ANY indentation then it will be invalid so be sure there's no indentation. Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee (Fake Private Key BTW)
is invalid and NOT the same as:
|
this one is really helping. Thank's for the answer |
Using HS256 works and produces the token key. but using RS256 throws the below error.
I'm using Google Cloud Compute servers if it makes any difference.
PHP Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /firebase/php-jwt/src/JWT.php on line 183
PHP Fatal error: Uncaught exception 'DomainException' with message 'OpenSSL unable to sign data' in /firebase/php-jwt/src/JWT.php:185\nStack trace:\n#0 /firebase/php-jwt/src/JWT.php(154): Firebase\JWT\JWT::sign('XXX...', 'XXX...', 'RS256')\n#1 /firebase.token.php(56): Firebase\JWT\JWT::encode(Array, 'XXX...', 'RS256')\n#2 /firebase.token.php(58): create_custom_token('MYUSER', false)\n#3 {main}\n thrown in /firebase/php-jwt/src/JWT.php on line 185
Thanks !
The text was updated successfully, but these errors were encountered: