src/VAPID.php
public static function createVapidKeys(): array
    {
        $curve = NistCurve::curve256();
        $privateKey = $curve->createPrivateKey();
        $publicKey = $curve->createPublicKey($privateKey);

        $binaryPublicKey = hex2bin(Utils::serializePublicKey($publicKey));
        if (!$binaryPublicKey) {
            throw new \ErrorException('Failed to convert VAPID public key from hexadecimal to binary');
        }

        $binaryPrivateKey = hex2bin(str_pad(gmp_strval($privateKey->getSecret(), 16), 2 * self::PRIVATE_KEY_LENGTH, '0', STR_PAD_LEFT));
        if (!$binaryPrivateKey) {
            throw new \ErrorException('Failed to convert VAPID private key from hexadecimal to binary');
        }

        return [
            'publicKey'  => Base64Url::encode($binaryPublicKey),
            'privateKey' => Base64Url::encode($binaryPrivateKey)
        ];
    }
public static function createVapidKeys(): array
    {
        $curve = NistCurve::curve256();
        $privateKey = $curve->createPrivateKey();
        $publicKey = $curve->createPublicKey($privateKey);

        $binaryPublicKey = hex2bin(Utils::serializePublicKey($publicKey));
        if (!$binaryPublicKey) {
            throw new \ErrorException('Failed to convert VAPID public key from hexadecimal to binary');
        }

        $binaryPrivateKey = hex2bin(str_pad(gmp_strval($privateKey->getSecret(), 16), 2 * self::PRIVATE_KEY_LENGTH, '0', STR_PAD_LEFT));
        if (!$binaryPrivateKey) {
            throw new \ErrorException('Failed to convert VAPID private key from hexadecimal to binary');
        }

        return [
            'publicKey'  => Base64Url::encode($binaryPublicKey),
            'privateKey' => Base64Url::encode($binaryPrivateKey)
        ];
    }
public static function createVapidKeys ( ) : array { $ curve = NistCurve :: curve256 ( ) ; $ privateKey = $ curve -> createPrivateKey ( ) ; $ publicKey = $ curve -> createPublicKey ( $ privateKey ) ; $ binaryPublicKey = hex2bin ( Utils :: serializePublicKey ( $ publicKey ) ) ; if ( ! $ binaryPublicKey ) { throw new \ ErrorException ( 'Failed to convert VAPID public key from hexadecimal to binary' ) ; } $ binaryPrivateKey = hex2bin ( str_pad ( gmp_strval ( $ privateKey -> getSecret ( ) , 16 ) , 2 * self :: PRIVATE_KEY_LENGTH , '0' , STR_PAD_LEFT ) ) ; if ( ! $ binaryPrivateKey ) { throw new \ ErrorException ( 'Failed to convert VAPID private key from hexadecimal to binary' ) ; } return [ 'publicKey' => Base64Url :: encode ( $ binaryPublicKey ) , 'privateKey' => Base64Url :: encode ( $ binaryPrivateKey ) ] ; }
This method creates VAPID keys in case you would not be able to have a Linux bash.
DO NOT create keys at each initialization! Save those keys and reuse them.

@return array
@throws \ErrorException
This method creates VAPID keys in case you would not be able to have a Linux bash . DO NOT create keys at each initialization! Save those keys and reuse them .