Skip to content

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

Closed
@melnikov-m-i

Description

@melnikov-m-i

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions