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

problem with PEM file key #33

Closed
sbraaa opened this issue Dec 29, 2023 · 3 comments
Closed

problem with PEM file key #33

sbraaa opened this issue Dec 29, 2023 · 3 comments

Comments

@sbraaa
Copy link

sbraaa commented Dec 29, 2023

I created a PEM file on server ubuntu 18 with openssl 1.1.1 using this code

 $privkey = openssl_pkey_new([
            'digest_alg' => 'sha256',
            'private_key_bits' => 1024,
            'private_key_type' => OPENSSL_KEYTYPE_RSA,
        ]);
        try {
            openssl_pkey_export_to_file($privkey, 'WEB-INF/config/' . $filename);
        } catch (Exception $e) {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
        }

on the same server it runs well, encoding and decoding as expected.

Then if I try the to decode using the same PEM file on different server (wich use openssl 1.1.1f) it doesn't run saying that signature is invalid.

Doing the same using a string instead of PEM file works. I cannot understand... could it be that PEM file I created depend on specficia server?

@adhocore
Copy link
Owner

it could be the openssl version too?

@sbraaa
Copy link
Author

sbraaa commented Jan 4, 2024

I guess it was my fault!
I tried to create jwt obj in SHA256 mode but pem file was created as RSA type

doing
$jwt = new JWT($key, 'RS384');
instead of
$jwt = new JWT($key, 'SHA256');
solve the problem

@sbraaa sbraaa closed this as completed Jan 4, 2024
@adhocore
Copy link
Owner

adhocore commented Jan 5, 2024

cool, thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants