perl kor
Crypt::JWT version: 0.035
Use of uninitialized value $5 in length at /usr/local/share/lib/perl5/Crypt/JWT.pm line 765.
Decoded JWT:
$VAR1 = {
'sub' => '1234567890',
'iat' => 1698214628,
'name' => 'John Doe'
};
Code:
use Crypt::JWT qw(encode_jwt decode_jwt);
use Crypt::OpenSSL::RSA;
use MIME::Base64;
use Data::Dumper;
my $version = $Crypt::JWT::VERSION;
print "Crypt::JWT version: $version\n";
# Generate a new RSA private key
my $rsa = Crypt::OpenSSL::RSA->generate_key(2048); # Adjust the key size as needed
# Get the private key as a string
my $private_key = $rsa->get_private_key_string();
# Create a JWT token using the private key (for demonstration purposes)
my $jwt = create_jwt_with_private_key($private_key);
# Decode the JWT
my $decoded = decode_jwt(
token => $jwt,
key => \$private_key,
algorithm => 'RS256', # Specify the RSA algorithm used
# You can specify additional options here
);
# Print the decoded data
print "Decoded JWT:\n";
print Dumper($decoded);
sub create_jwt_with_private_key {
my ($private_key) = @_;
# Example: Create a JWT using the private key (for demonstration purposes)
my $claims = {
sub => '1234567890',
name => 'John Doe',
iat => time(),
};
my $jwt = encode_jwt(payload => $claims, alg => 'RS256', key => \$private_key);
return $jwt;
}
Example:
Code: