-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypt_rsa_sign.pl
51 lines (39 loc) · 1.39 KB
/
crypt_rsa_sign.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
# Using Crypt::RSA to sign a message, using an explicitly given private key.
use 5.014;
use Crypt::RSA;
my $rsa = Crypt::RSA->new;
my $key = Crypt::RSA::Key->new;
my ($public, $private) =
$key->generate(
p => "99554414790940424414351515490472769096534141749790794321708050837",
q => "104593961812606247801193807142122161186583731774511103180935025763",
e => 65537,
)
or die "error";
my $message = "Hello world!";
my $signature = $rsa->sign(
Message => $message,
Key => $private,
Armour => 1,
)
|| die $rsa->errstr();
say $signature;
my $plaintext = $rsa->verify(
Signature => $signature,
Message => $message,
Key => $public,
Armour => 1,
)
|| die $rsa->errstr();
say ("Valid signature: ", ($plaintext ? "yes" : "no"));
#~ $public->write ( Filename => 'cicada.public' );
#~ $private->write ( Filename => 'cicada.private' );
__END__
-----BEGIN RSA SIGNATURE-----
Version: 1.99
Scheme: Crypt::RSA::SS::PSS
OQA1NABTaWduYXR1cmXV7WLmAUf4OxAMgmi7zg+29Mkp01JE3wrrBFoycR4q5WuaHyahJUwugSW/
84TmB5IZ2Z3TPEw=
=8zvlSo9cU7Merm4hrEJboQ==
-----END RSA SIGNATURE-----