|
Posted by Mumia W. on March 13, 2007, 6:04 am
Please log in for more thread options
On 03/12/2007 11:28 AM, rjvennes@hotmail.com wrote:
> The CGI script only need to exist for a single process... nothing
> needs to be passed to another process.
>
> Using Mumia suggestion of:
>
> use Data::Dumper;
> $key->deserialize(String => Dumper($PrivateKey));
>
> didn't seem to work either. [...]
After looking at the source, I see that the deserialize method *returns*
a new key object that contains the required data:
my $newkey = $key->deserialize(String => [ $PrivateKey ] );
# use $newkey to decrypt the message.
The code above assumes that $PrivateKey is a string created with
$key->write(). Notice that the $PrivateKey must be enclosed within an
anonymous array. Notice that the documentation does not say this.
Here is a program that doesn't demonstrate using
Crypt::RSA::Key::Private very well. I get an error, "n is not a number,"
from this program, but I still hope it helps you some:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Crypt::RSA;
use Crypt::RSA::Key::Private;
use File::Slurp;
my $PrivateKey = read_file('key.private');
my $message = read_file('cypher.data');
my $rsa = new Crypt::RSA;
my $nokey = Crypt::RSA::Key::Private->new;
my $privkey = $nokey->deserialize(String => [$PrivateKey]);
my $plaintext;
$plaintext = $rsa->decrypt(
Cyphertext => $message,
Key => $privkey,
Armour => 1,
) or die $rsa->errstr;
print $plaintext;
__END__
|