Sample code for 30+ languages & platforms
Perl

Get the JWE Protected Header

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetProtectedHeader, which copies the decoded shared JWE protected header into a JsonObject.

Background. Only the protected header is returned; it is not merged with the shared unprotected header or any per-recipient header.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $jwe = Chilkat2::Jwe->new;

# Load the JWE.
my $jweCompact = 'eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>';
my $success = $jwe->LoadJwe($jweCompact);
if (!$success) {
    print $jwe->LastErrorText, "\n";
    exit;
}

# Copy the decoded shared JWE protected header into a JsonObject.  Only the protected header is
# returned; it is not merged with the unprotected or per-recipient headers.
my $json = Chilkat2::JsonObject->new;
$success = $jwe->GetProtectedHeader($json);
if (!$success) {
    print $jwe->LastErrorText, "\n";
    exit;
}

$json->EmitCompact(0);
print $json->Emit(), "\n";