line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -sw |
2
|
|
|
|
|
|
|
## |
3
|
|
|
|
|
|
|
## Crypt::RSA::Key::Public |
4
|
|
|
|
|
|
|
## |
5
|
|
|
|
|
|
|
## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved. |
6
|
|
|
|
|
|
|
## This code is free software; you can redistribute it and/or modify |
7
|
|
|
|
|
|
|
## it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
## |
9
|
|
|
|
|
|
|
## $Id: Public.pm,v 1.8 2001/09/25 14:11:23 vipul Exp $ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Crypt::RSA::Key::Public; |
12
|
1
|
|
|
1
|
|
10686
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
13
|
1
|
|
|
1
|
|
5
|
use vars qw($AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
14
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
15
|
1
|
|
|
1
|
|
1023
|
use Data::Dumper; |
|
1
|
|
|
|
|
11280
|
|
|
1
|
|
|
|
|
92
|
|
16
|
1
|
|
|
1
|
|
8
|
use base 'Crypt::RSA::Errorhandler'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
583
|
|
17
|
1
|
|
|
1
|
|
1691
|
use Math::Pari qw(PARI pari2pv); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$Crypt::RSA::Key::Public::VERSION = '1.99'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my ($class, %params) = @_; |
24
|
|
|
|
|
|
|
my $self = { Version => $Crypt::RSA::Key::Public::VERSION }; |
25
|
|
|
|
|
|
|
if ($params{Filename}) { |
26
|
|
|
|
|
|
|
bless $self, $class; |
27
|
|
|
|
|
|
|
$self = $self->read (%params); |
28
|
|
|
|
|
|
|
return bless $self, $class; |
29
|
|
|
|
|
|
|
} else { |
30
|
|
|
|
|
|
|
return bless $self, $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub AUTOLOAD { |
37
|
|
|
|
|
|
|
my ($self, $value) = @_; |
38
|
|
|
|
|
|
|
my $key = $AUTOLOAD; $key =~ s/.*:://; |
39
|
|
|
|
|
|
|
if ($key =~ /^n|e$/) { |
40
|
|
|
|
|
|
|
if (ref $value eq 'Math::Pari') { |
41
|
|
|
|
|
|
|
$self->{$key} = pari2pv($value) |
42
|
|
|
|
|
|
|
} elsif ($value && !(ref $value)) { |
43
|
|
|
|
|
|
|
if ($value =~ /^0x/) { |
44
|
|
|
|
|
|
|
$self->{$key} = pari2pv(Math::Pari::_hex_cvt($value)); |
45
|
|
|
|
|
|
|
} else { $self->{$key} = $value } |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
my $return = $self->{$key} || ""; |
48
|
|
|
|
|
|
|
$return = PARI("$return") if $return =~ /^\d+$/; |
49
|
|
|
|
|
|
|
return $return; |
50
|
|
|
|
|
|
|
} elsif ($key =~ /^Identity$/) { |
51
|
|
|
|
|
|
|
$self->{$key} = $value if $value; |
52
|
|
|
|
|
|
|
return $self->{$key}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub DESTROY { |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
undef $self; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub check { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
return $self->error ("Incomplete key.") unless $self->n && $self->e; |
70
|
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub write { |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my ($self, %params) = @_; |
78
|
|
|
|
|
|
|
$self->hide(); |
79
|
|
|
|
|
|
|
my $string = $self->serialize (%params); |
80
|
|
|
|
|
|
|
open DISK, ">$params{Filename}" or |
81
|
|
|
|
|
|
|
croak "Can't open $params{Filename} for writing."; |
82
|
|
|
|
|
|
|
binmode DISK; |
83
|
|
|
|
|
|
|
print DISK $string; |
84
|
|
|
|
|
|
|
close DISK; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub read { |
90
|
|
|
|
|
|
|
my ($self, %params) = @_; |
91
|
|
|
|
|
|
|
open DISK, $params{Filename} or |
92
|
|
|
|
|
|
|
croak "Can't open $params{Filename} to read."; |
93
|
|
|
|
|
|
|
binmode DISK; |
94
|
|
|
|
|
|
|
my @key = ; |
95
|
|
|
|
|
|
|
close DISK; |
96
|
|
|
|
|
|
|
$self = $self->deserialize (String => \@key); |
97
|
|
|
|
|
|
|
return $self; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub serialize { |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ($self, %params) = @_; |
104
|
|
|
|
|
|
|
return Dumper $self; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub deserialize { |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my ($self, %params) = @_; |
112
|
|
|
|
|
|
|
my $string = join'', @{$params{String}}; |
113
|
|
|
|
|
|
|
$string =~ s/\$VAR1 =//; |
114
|
|
|
|
|
|
|
$self = eval $string; |
115
|
|
|
|
|
|
|
return $self; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 NAME |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Crypt::RSA::Key::Public -- RSA Public Key Management. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SYNOPSIS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$key = new Crypt::RSA::Key::Public; |
129
|
|
|
|
|
|
|
$key->write ( Filename => 'rsakeys/banquo.public' ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$akey = new Crypt::RSA::Key::Public ( |
132
|
|
|
|
|
|
|
Filename => 'rsakeys/banquo.public' |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DESCRIPTION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Crypt::RSA::Key::Public provides basic key management functionality for |
139
|
|
|
|
|
|
|
Crypt::RSA public keys. Following methods are available: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item B |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The constructor. Reads the public key from a disk file when |
146
|
|
|
|
|
|
|
called with a C argument. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item B |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Causes the key to be written to a disk file specified by the |
151
|
|
|
|
|
|
|
C argument. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item B |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Causes the key to be read from a disk file specified by |
156
|
|
|
|
|
|
|
C into the object. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item B |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Creates a Data::Dumper(3) serialization of the private key and |
161
|
|
|
|
|
|
|
returns the string representation. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item B |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Accepts a serialized key under the C parameter and |
166
|
|
|
|
|
|
|
coverts it into the perl representation stored in the object. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item C |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Check the consistency of the key. Returns undef on failure. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHOR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Vipul Ved Prakash, Email@vipul.netE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Crypt::RSA::Key(3), Crypt::RSA::Key::Private(3) |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|