Skip to content
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

ECDH-ES+A256KW + A256GCM error #590

Open
parsibox opened this issue Nov 14, 2024 · 0 comments
Open

ECDH-ES+A256KW + A256GCM error #590

parsibox opened this issue Nov 14, 2024 · 0 comments

Comments

@parsibox
Copy link

Description

hi
i want to create jwe same as this image
image
this is my php code

<?php

require 'vendor/autoload.php';

use Jose\Component\Core\JWK;
use Jose\Component\Encryption\Algorithm\KeyEncryption\ECDHESA256KW;
use Jose\Component\Encryption\Algorithm\ContentEncryption\A256GCM;
use Jose\Component\Encryption\Compression\CompressionMethodManager;
use Jose\Component\Encryption\JWEBuilder;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\KeyManagement\JWKFactory;
$privateKey = <<<EOD
-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIBVJmxxvH8Kp2bKVZHzr9W576vdSxnPdnk7X5+Cb53gQXJIS53IaoZ
8W7JIB2BJTgBGqa8WC5X8tX32SEgjF6YuxugBwYFK4EEACOhgYkDgYYABABDpgDm
15S3O/PywiKeW0LN1gu05xqJB3huWt+5qQxK16mwkAWQTmofW8+FBKEM9jzOUW/3
SStW90PMcXBtxpT0FAF5Kjq5LkIjAW9NIbQtr+PGS5HYBEBKcmCiFa1hA5hRyM97
y/XzZx+EZsDmBdL7p9sQkNb/MVexHr3eoH19VZrb7g==
-----END EC PRIVATE KEY-----
EOD;

// Define the payload
$payload = [
    'data' => 'eyJhbGciOiJFUzUxMiIsImNsaWVudElEIjoiYzVkNzhmMTAtMmY3NS00ZmM5LWE2ZTAtNmQ0YzViNWM0ZTU5In0.eyJwYXRoIjoiL3NlcnZpY2UxIiwiZGF0YSI6IntcclxuICAgIFwicmVxdWVzdElkXCI6IFwiMTIzNDU2Nzg5MFwiXHJcbn0iLCJtZXRob2QiOiJQT1NUIiwiaWF0IjoxNzMxNTc1NjEyfQ.AQZoZJSi75hHyQDGc6zQMn05yWe9pdA-BNRgUfLwWXmM_6LNrbLuANeXTkJvJfmMCwCvAoNSOVefvKHyrnjv6P9yAV05RRHIgl6vtpNruYGFXdVfQaYygIDeUhbZlv_l4ETmfmxwhMWr9POxMmmokuIloNoNzy86W3lfA0TZIKLwOmzU',
    'iat' => 1731575612,
];


$publicKeyPem = <<<EOD
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtB7W2BLDBSjJv1danzZeOjQGhCOe
u3u/JIIVXFrdbfi3vi7t+EQJY5H7df1YcO0tu9LstL260DJba72IQQZDCg==
-----END PUBLIC KEY-----
EOD;
$recipientPublicKeyJWK = JWKFactory::createFromKey($publicKeyPem);

// Set up algorithms
$keyEncryptionAlgorithmManager = new AlgorithmManager([new ECDHESA256KW()]);
$contentEncryptionAlgorithmManager = new AlgorithmManager([new A256GCM()]);
$compressionMethodManager = new CompressionMethodManager([]); // No compression


// Initialize JWE Builder
$jweBuilder = new JWEBuilder(
    $keyEncryptionAlgorithmManager,
    $contentEncryptionAlgorithmManager
    , $compressionMethodManager
);

// Build the JWE
$jwe = $jweBuilder
    ->create()
    ->withPayload(json_encode($payload))
    ->withSharedProtectedHeader([
        'alg' => 'ECDH-ES+A256KW',
        'enc' => 'A256GCM',
    ])
    ->addRecipient($recipientPublicKeyJWK)
    ->build();

but it say:

<html>
<body>
<!--StartFragment-->
( ! ) Fatal error: Uncaught RuntimeException: Unable to create the key in  \php\vendor\web-token\jwt-framework\src\Component\Core\Util\ECKey.php on line 148
--


<br class="Apple-interchange-newline"><!--EndFragment-->
</body>
</html>
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