web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.71k stars 299 forks source link

VAPID. Warning: hex2bin(): Hexadecimal input string must have an even length #56

Closed degtyaryov closed 7 years ago

degtyaryov commented 7 years ago

Hello.

VAPID sometimes does not work.

hex2bin return false and warning.

My solution:

$privateKeyObject = EccFactory::getNistCurves()->generator256()->createPrivateKey();
$hex = gmp_strval($privateKeyObject->getSecret(), 16);
if (strlen($hex) % 2 != 0) {
    $hex = '0'.$hex;
}
$vapid['privateKey'] = base64_encode(hex2bin($hex));
yourchoice commented 7 years ago

Same at me, but initially worked:

PHP Warning: hex2bin(): Hexadecimal input string must have an even length in ...\vendor\minishlink\web-push\src\VAPID.php on line 147 PHP Stack trace: PHP 1. {main}() ...\batch\batch_wpn.php:0 PHP 2. wpn->genVAPIDKeys() ....\batch\batch_wpn.php:13 PHP 3. Minishlink\WebPush\VAPID::createVapidKeys() ...\component\wpn.class.php:692 PHP 4. hex2bin() ...\vendor\minishlink\web-push\src\VAPID.php:147

Warning: hex2bin(): Hexadecimal input string must have an even length in ...\vendor\minishlink\web-push\src\VAPID.php on line 147

Just one time happened this warning. Now seems to work, without any changes

Minishlink commented 7 years ago

Hi, thanks for the feedback. I'll put a fix asap.