line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::WebToken::Crypt::RSA; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1759
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
87
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
5
|
2
|
|
|
2
|
|
12
|
use parent 'JSON::WebToken::Crypt'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
89
|
use Crypt::OpenSSL::RSA (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
405
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $ALGORITHM2SIGNING_METHOD_MAP = { |
10
|
|
|
|
|
|
|
RS256 => 'use_sha256_hash', |
11
|
|
|
|
|
|
|
RS384 => 'use_sha384_hash', |
12
|
|
|
|
|
|
|
RS512 => 'use_sha512_hash', |
13
|
|
|
|
|
|
|
RSA1_5 => 'use_pkcs1_padding', |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub sign { |
17
|
4
|
|
|
4
|
0
|
10
|
my ($class, $algorithm, $message, $key) = @_; |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
171
|
my $private_key = Crypt::OpenSSL::RSA->new_private_key($key); |
20
|
4
|
|
|
|
|
24
|
my $method = $ALGORITHM2SIGNING_METHOD_MAP->{$algorithm}; |
21
|
4
|
|
|
|
|
22
|
$private_key->$method; |
22
|
4
|
|
|
|
|
11422
|
return $private_key->sign($message); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub verify { |
26
|
4
|
|
|
4
|
0
|
9
|
my ($class, $algorithm, $message, $key, $signature) = @_; |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
103
|
my $public_key = Crypt::OpenSSL::RSA->new_public_key($key); |
29
|
4
|
|
|
|
|
1466
|
my $method = $ALGORITHM2SIGNING_METHOD_MAP->{$algorithm}; |
30
|
4
|
|
|
|
|
20
|
$public_key->$method; |
31
|
4
|
50
|
|
|
|
462
|
return $public_key->verify($message, $signature) ? 1 : 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |