Alt-Crypt-RSA-BigInt
view release on metacpan or search on metacpan
Changes.old view on Meta::CPAN
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
}
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
$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
=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
#$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
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.318 second using v1.01-cache-2.11-cpan-cba739cd03b )