Skip to content

An error occurs: "[VAPID] Private key should be 32 bytes long when decoded". #427

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

Closed
melnikov-m-i opened this issue Mar 11, 2025 · 1 comment

Comments

@melnikov-m-i
Copy link

When specifying a key in pem format, an error occurs. Namely, in the VAPID class, in the validate method.
The following point is confusing:

// Line: 57
$vapid['privateKey'] = base64_encode(str_pad(Base64Url::decode($jwk->get('d')), 2 * self::PRIVATE_KEY_LENGTH, '0', STR_PAD_LEFT));

// Line: 76
if (Utils::safeStrlen($privateKey) !== self::PRIVATE_KEY_LENGTH) {
    throw new \ErrorException('[VAPID] Private key should be 32 bytes long when decoded.');
}

That is, first the length of the key is doubled, adding 0 to the left. And then it is compared with the normal length.
Is this a mistake? Or not? Can someone explain it to me, if it's not too much trouble.

@melnikov-m-i
Copy link
Author

Resolved in #414 and merged into version 9.

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

1 participant