Alt-Crypt-RSA-BigInt
view release on metacpan or search on metacpan
lib/Crypt/RSA/Key/Public.pm view on Meta::CPAN
package Crypt::RSA::Key::Public;
use strict;
use warnings;
## Crypt::RSA::Key::Public
##
## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved.
## This code is free software; you can redistribute it and/or modify
## it under the same terms as Perl itself.
use vars qw($AUTOLOAD);
use Carp;
use Data::Dumper;
use base 'Crypt::RSA::Errorhandler';
use Math::BigInt try => 'GMP, Pari';
$Crypt::RSA::Key::Public::VERSION = '1.99';
sub new {
my ($class, %params) = @_;
my $self = { Version => $Crypt::RSA::Key::Public::VERSION };
if ($params{Filename}) {
bless $self, $class;
$self = $self->read (%params);
return bless $self, $class;
} else {
return bless $self, $class;
}
}
sub AUTOLOAD {
my ($self, $value) = @_;
my $key = $AUTOLOAD; $key =~ s/.*:://;
if ($key =~ /^n|e$/) {
if (defined $value) {
if (ref $value eq 'Math::BigInt') {
$self->{$key} = $value;
} elsif (ref $value eq 'Math::Pari') {
$self->{$key} = Math::BigInt->new($value->pari2pv);
} else {
$self->{$key} = Math::BigInt->new("$value");
}
}
if (defined $self->{$key}) {
$self->{$key} = Math::BigInt->new("$self->{$key}") unless ref($self->{$key}) eq 'Math::BigInt';
return $self->{$key};
}
return;
} elsif ($key =~ /^Identity$/) {
$self->{$key} = $value if $value;
return $self->{$key};
}
}
sub DESTROY {
my $self = shift;
undef $self;
}
sub check {
my $self = shift;
return $self->error ("Incomplete key.")
unless defined $self->n && defined $self->e;
return 1;
}
sub write {
my ($self, %params) = @_;
$self->hide();
my $string = $self->serialize (%params);
open(my $disk, '>', $params{Filename}) or
croak "Can't open $params{Filename} for writing.";
binmode $disk;
print $disk $string;
close $disk;
}
( run in 0.730 second using v1.01-cache-2.11-cpan-d7f47b0818f )