简体   繁体   中英

How do I get Crypt::RSA to show its public and private keys that have been generated?

Hi there I am messing around with the Crypt::RSA perl modules. I have gotten the modules to encrypt a string (password) and then export it to a file called "test.key" But it occurred to me that the cipher is no good if I cannot get at the key used to encrypt the string in the first place.

When I try to have it simply print the scalar $private and $public, I get a HASH(0x00000) looking output. So as far I can gather that means the key is store in a HASH, the problem is I don't know the name of the HASH created in order to print the key in question. It says parameters for Crypt::RSA can be found in a man page that apparently does not exist on my system.

Any ideas?

Here is the sample code I have tore apart.

#!/usr/bin/perl

use strict;

use warnings;
use Crypt::RSA;
my $rsa = new Crypt::RSA;
my $message = "hello world";
my ($public, $private) = $rsa->keygen ( 
    #Identity  => '',
    Size      => 1024,  
    #Password  => '', 
    Verbosity => 1,
    ) or die $rsa->errstr();

my $cyphertext = $rsa->encrypt ( 
    Message    => $message,
    Key        => $public,
    Armour     => 1,
    ) or die $rsa->errstr();

my $plaintext = $rsa->decrypt ( 
    Cyphertext => $cyphertext, 
    Key        => $private,
    Armour     => 1,
    ) or die $rsa->errstr();

print $public;

print $private;

open FILE, ">", "test.key" or die $!;
print FILE "$cyphertext\n";
close FILE;

Documentation for modules can be found on CPAN , and should be installed on your system ( perldoc Crypt::RSA ).

Here is the relevant link: http://search.cpan.org/dist/Crypt-RSA/

From there, you want to see the following pages that describe the method based interface to the key variables.

For the future, please post the exact output your script produces. In this case, chances are that output contains your answer (the module names of the objects you are trying to print). Then the documentation is just a search away.

In this case, its probably something like:

print $_->serialize, "\n" for $public, $private;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM