Net-API-REST
view release on metacpan or search on metacpan
lib/Net/API/REST/JWT.pm view on Meta::CPAN
die( "JWT: invalid RSA key (cannot be scalar)" ) unless( ref( $key ) );
# we need Crypt::PK::RSA object
return( $key ) if( ref( $key ) eq 'Crypt::PK::RSA' );
return( Crypt::PK::RSA->new( $key ) ) if( ref( $key ) eq 'HASH' || ref( $key ) eq 'SCALAR' );
return( Crypt::PK::RSA->new( @$key ) ) if( ref( $key ) eq 'ARRAY' );
# handle also: Crypt::OpenSSL::RSA, Crypt::X509, Crypt::OpenSSL::X509
my $str;
if( ref( $key ) eq 'Crypt::OpenSSL::RSA' )
{
# https://metacpan.org/pod/Crypt::OpenSSL::RSA
$str = $key->is_private ? $key->get_private_key_string : $key->get_public_key_string;
}
elsif( ref( $key ) =~ /^Crypt::(X509|OpenSSL::X509)$/ )
{
# https://metacpan.org/pod/Crypt::X509
# https://metacpan.org/pod/Crypt::OpenSSL::X509
$str = $key->pubkey;
}
return( Crypt::PK::RSA->new( \$str ) ) if( defined( $str ) && !ref( $str ) );
die( "JWT: invalid RSA key" );
}
lib/Net/API/REST/JWT.pm view on Meta::CPAN
#a reference to SCALAR string with PEM or DER or JSON/JWK data,
my $data = decode_jwt(token=>$t, key=>\$pem_key_string);
my $data = decode_jwt(token=>$t, key=>\$der_key_string);
my $data = decode_jwt(token=>$t, key=>\$jwk_key_json_string);
#instance of Crypt::PK::RSA
my $data = decode_jwt(token=>$t, key=>Crypt::PK::RSA->new('keyfile.pem'));
my $data = decode_jwt(token=>$t, key=>Crypt::PK::RSA->new(\$pem_key_string));
#instance of Crypt::OpenSSL::RSA
my $data = decode_jwt(token=>$t, key=>Crypt::OpenSSL::RSA->new_private_key($pem_key_string));
#instance of Crypt::X509 (public key only)
my $data = decode_jwt(token=>$t, key=>Crypt::X509->new(cert=>$cert));
#instance of Crypt::OpenSSL::X509 (public key only)
my $data = decode_jwt(token=>$t, key=>Crypt::OpenSSL::X509->new_from_file('cert.pem'));
my $data = decode_jwt(token=>$t, key=>Crypt::OpenSSL::X509->new_from_string($cert));
#perl HASH ref with JWK structure (key type 'RSA')
my $rsa_priv = {
( run in 0.316 second using v1.01-cache-2.11-cpan-4d50c553e7e )