Skip to content

Creating an OKP with JWKFactory creates too long a private key for signing #165

Closed
@moderndeveloperllc

Description

@moderndeveloperllc

Describe the bug
When using JWKFactory::createOKPKey(Ed25519) a 64 byte secret key is created. When used to sign a token, a SodiumException is thrown:

seed should be SODIUM_CRYPTO_SIGN_SEEDBYTES bytes

Note that the constant is defined as 32. Your tests for OKP creation and signing use a manually created 32 byte private key d.

PHP Version: 7.3.2

To Reproduce
Steps to reproduce the behavior:

$key = JWKFactory::createOKPKey('Ed25519');
$algorithmManager = AlgorithmManager::create([new EdDSA()]);
$jwsBuilder = new JWSBuilder(new StandardConverter(), $algorithmManager);

$jwtSigned = $jwsBuilder
            ->create()
            ->withPayload('')
            ->addSignature(
                $key,
                [
                    'crit' => ['exp', 'aud'],
                    'alg'  => ''EdDSA',
                ]
            )
            ->build();

Expected behavior
The token to be signed.

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