diff --git a/src/Component/KeyManagement/KeyConverter/KeyConverter.php b/src/Component/KeyManagement/KeyConverter/KeyConverter.php index 96498b9e..c7b69e5d 100644 --- a/src/Component/KeyManagement/KeyConverter/KeyConverter.php +++ b/src/Component/KeyManagement/KeyConverter/KeyConverter.php @@ -252,12 +252,14 @@ private static function tryToLoadOtherKeyTypes(string $input): array private static function populatePoints(PrivateKey $key, array $values): array { $x = self::getPublicKey($key, $values['crv']); - $values['x'] = Base64UrlSafe::encodeUnpadded($x); + if ($x !== null) { + $values['x'] = Base64UrlSafe::encodeUnpadded($x); + } return $values; } - private static function getPublicKey(PrivateKey $key, string $crv): string + private static function getPublicKey(PrivateKey $key, string $crv): ?string { switch ($crv) { case 'Ed25519': @@ -268,7 +270,7 @@ private static function getPublicKey(PrivateKey $key, string $crv): string } // no break default: - throw new InvalidArgumentException('Unsupported key type'); + return null; } } diff --git a/src/SignatureAlgorithm/EdDSA/composer.json b/src/SignatureAlgorithm/EdDSA/composer.json index a5595bc5..b1223f9d 100644 --- a/src/SignatureAlgorithm/EdDSA/composer.json +++ b/src/SignatureAlgorithm/EdDSA/composer.json @@ -40,6 +40,7 @@ "require": { "php": ">=8.1", "ext-sodium": "*", + "paragonie/sodium_compat": "^1.20", "web-token/jwt-signature": "^3.2" } } diff --git a/tests/Component/KeyManagement/JWKFactoryTest.php b/tests/Component/KeyManagement/JWKFactoryTest.php index 4f83ab07..c777b503 100644 --- a/tests/Component/KeyManagement/JWKFactoryTest.php +++ b/tests/Component/KeyManagement/JWKFactoryTest.php @@ -297,7 +297,7 @@ public static function dataKeys(): iterable 'kty' => 'OKP', 'crv' => 'Ed25519', 'd' => 'Pr9AxZivB-zSq95wLrZfYa7DQ3TUPqZTkP_0w33r3rc', - 'x' => 'uRhai1TsvrSB43HD-36TQ2hMQfV8ruJz7F8o0wIe1VI', + 'x' => 'wrI33AEj15KHHYplueUE5cnJKtbM8oVHFf6wGnw2oOE', ], ]; yield [