Here is my current code.
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Core\JWK;
use Jose\Component\Signature\Algorithm\ES256;
use Jose\Component\Signature\JWSBuilder;
$algorithm_manager = new AlgorithmManager([
new ES256(),
]);
$header = array("zip" => "DEF","alg" => "ES256","kid" => "...kid...");
$payload = array("info...");
$js = json_encode($payload,JSON_UNESCAPED_SLASHES);
$jwk = new JWK([
'kty' => 'ES256',
'k' => '...kid...',
]);
$jwsBuilder = new JWSBuilder($algorithm_manager);
$jws = $jwsBuilder
->create() // We want to create a new JWS
->withPayload($js) // We set the payload
->addSignature($jwk, ['alg' => 'ES256']) // We add a signature with a simple protected header
->build();
$serializer = new CompactSerializer(); // The serializer
$token = $serializer->serialize($jws, 0); // We serialize the signature at index 0 (we only have one signature).
Whenever I try to serialize this it tells me this error.
Fatal error: Uncaught InvalidArgumentException: Wrong key type. in vendor/web-token/jwt-framework/src/SignatureAlgorithm/ECDSA/ECDSA.php:72
This is the first time i'm using this software so i may be forgetting a step or something.
Would some one be so kind as to point me to where im going wrong?