Alt-Crypt-RSA-BigInt

 view release on metacpan or  search on metacpan

Changes.old  view on Meta::CPAN

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    hash of Makefile.PL.
 
  * ::Key loads ::Key::Private and ::Key::Public by default.
 
1.42                                                          May 24, 2001
   
  * Speed optimizations throughout.
 
  * Documented Crypt::RSA and Crypt::RSA::Key.
 
  * ::Key::Private::read() will call reveal() if the password is provided
    at construction.
 
  * Added support for unencrypted keys to ::Key::Private.
 
  * ::Key::Private does not convert pari2pv at every STORE().
    Tie::EncryptedHash is created explicitely at hide().
     
  * Put together ::Key::Private::SSH from Benjamin Trott's patches and
    wrote ::Key::Public::SSH. ::Key::Private::SSH's CBC encryption is
    not compatible with SSH yet.

lib/Crypt/RSA/Key/Private.pm  view on Meta::CPAN

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
}
 
 
sub hide {
 
    my ($self) = @_;
 
    return unless $$self{Password};
 
    $self->{private_encrypted} = new Tie::EncryptedHash
            __password => $self->{Password},
            __cipher   => $self->{Cipher};
 
    for (keys %{$$self{private}}) {
        $$self{private_encrypted}{$_} = $$self{private}{$_}->bstr;
    }
 
    my $private = $self->{private_encrypted};
    delete $private->{__password};
    delete $$self{private};
    delete $$self{Password};
 
    # Mark ourselves as hidden
    $self->{Hidden} = 1;
}
 
 
sub reveal {
 
    my ($self, %params) = @_;
    $$self{Password} = $params{Password} if $params{Password};
    return unless $$self{Password};
    $$self{private_encrypted}{__password} = $params{Password};
    for (keys %{$$self{private_encrypted}}) {
        $$self{private}{$_} = Math::BigInt->new("$$self{private_encrypted}{$_}");
    }
    $self->{Hidden} = 0;
 
}
 
 
sub check {

lib/Crypt/RSA/Key/Private.pm  view on Meta::CPAN

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    $self->Checked(1);
    return 1;
 
}
 
 
sub DESTROY {
 
    my $self = shift;
    delete $$self{private_encrypted}{__password};
    delete $$self{private_encrypted};
    delete $$self{private};
    delete $$self{Password};
    undef $self;
 
}
 
 
sub write {

lib/Crypt/RSA/Key/Private.pm  view on Meta::CPAN

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
=back
 
=item B<reveal()>
 
If the key is not decrypted at C<new()>, it can be decrypted by
calling C<reveal()> with a C<Password> argument.
 
=item B<hide()>
 
C<hide()> causes the key to be encrypted by the chosen symmetric cipher
and password.
 
=item B<write()>
 
Causes the key to be written to a disk file specified by the
C<Filename> argument. C<write()> will call C<hide()> before
writing the key to disk. If you wish to store the key in plain,
don't specify a password at C<new()>.
 
=item B<read()>
 
Causes the key to be read from a disk file specified by
C<Filename> into the object. If C<Password> is provided, the
method automatically calls reveal() to decrypt the key.
 
=item B<serialize()>
 
Creates a Data::Dumper(3) serialization of the private key and

lib/Crypt/RSA/Key/Private/SSH.pm  view on Meta::CPAN

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    #$key->{Password} = $passphrase unless defined $key->{Password};
 
    $key;
}
 
 
sub serialize {
    my($key, %params) = @_;
 
    # We could reveal it, but (1) what if it was hidden with a different
    # password, and (2) they may not want to revealed (even if hidden after).
    croak "Cowardly refusing to serialize a hidden key"
      if $key->{Hidden};
 
    my $passphrase = defined $params{Password} ? $params{Password}
                   : defined $key->Password    ? $key->Password
                   : '';
    my $cipher_name = defined $params{Cipher} ? $params{Cipher}
                    : defined $key->Cipher    ? $key->Cipher
                    : 'Blowfish';

t/18-private-ssh.t  view on Meta::CPAN

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  my $s = $pri->serialize( Cipher => $cipher, Password => 'serpent' );
 
  my ($newpub, $newpri) = $obj->generate( Size => 128, KF => 'SSH', );
 
  # Do it incorrectly first.  Should croak.
  eval { $newpri->deserialize( String => $s, Password => "mst" ); };
  like($@, qr/passphrase/i, "Bad passphrase will croak");
 
  $newpri->deserialize( String => $s, Password => "serpent" );
  # newpri should have no password assigned
  $newpri->{Password} = 'guess';
   
  is_deeply( $newpri, $pri, "private key fully deserialized using $cipher");
 
}



( run in 0.404 second using v1.01-cache-2.11-cpan-cba739cd03b )