laravel-notification-channels/webpush

When generating VAPID keys getting an error

Closed this issue · 8 comments

When trying to generate VAPID keys on the terminal, I got an error: "Unable to create the key".
error

Using:
Laravel: 8.x, PHP: 7.4
Any suggestions?

Do you find any solution?

Do you find any solution?

I tested this on several Laravel projects. One was written on Laravel 8, another written on Laravel 5.7. Only on the Laravel 5.7 project, I manage to generate VAPID keys.

You need to install the OpenSSL to resolved this problem

i already enable OpenSSL in xampp extension but still not working. i am using windows 10.

Maybe you can try this way:
https://stackoverflow.com/questions/17272809/openssl-pkey-export-and-cannot-get-key-from-parameter-1/18869750#18869750
on step9, I used "c:\xampp\apache\conf\openssl.cnf".
My Laravel is 8.7x and windows 10,and keep ";extension=openssl" on php.ini.
Hope it can help you.

php artisan webpush:vapid

   RuntimeException

  Unable to create the key

  at C:\laragon\www\laravel-webPush-Notification\vendor\web-token\jwt-core\Util\
ECKey.php:160
    156|             'curve_name' => self::getOpensslCurveName($curve),
    157|             'private_key_type' => OPENSSL_KEYTYPE_EC,
    158|         ]);
    159|         if (false === $key) {
  > 160|             throw new RuntimeException('Unable to create the key');
    161|         }
    162|         $result = openssl_pkey_export($key, $out);
    163|         if (false === $result) {
    164|             throw new RuntimeException('Unable to create the key');

  1   C:\laragon\www\laravel-webPush-Notification\vendor\web-token\jwt-core\Util
\ECKey.php:119
      Jose\Component\Core\Util\ECKey::createECKeyUsingOpenSSL("P-256")

  2   C:\laragon\www\laravel-webPush-Notification\vendor\web-token\jwt-key-mgmt\
JWKFactory.php:78
      Jose\Component\Core\Util\ECKey::createECKey("P-256", [])

Even with open ssl, laravel version 8 gives an error while creating vapid key. There is no error in laravel 5, but I did not find a valid solution for laravel 8.

If you're on Windows, the easiest way is to install openssl with scoop like this:

scoop install openssl

Then the VAPID keys will be created successfully:

php artisan webpush:vapid