http://www.perlmonks.org?node_id=1208799

iglake has asked for the wisdom of the Perl Monks concerning the following question:

I am experimenting with RSA keys and the Crypt::RSA module is seems that Native formate can be read back without problems, however when using the key format to ssh, the module doesn't seem to understand the format of the file is previously created.

Anyone have experience with reading in keys with Crypt::RSA ?

(note I am running a box with ubuntu 16.04)

The script

here is my code :

#!/usr/bin/perl use Crypt::RSA; my $Identity = 'Lord Banquo <banquo@lochaber.com>'; my $Password = 'The earth hath bubbles'; my $KF = 'SSH'; my ($public, $private); my $kf = lc(substr($KF,0,3)); my $priv_key_file = sprintf('id_rsa_%s.sec',$kf); # --------------------------------------------------- if ( ! -e $priv_key_file ) { # key pair generation : my $rsa = new Crypt::RSA; ($public, $private) = $rsa->keygen( Identity => $Identity, Size => 1024, Cipher => 'Twofish', Password => $Password, Verbosity => 0, KF => $KF, #Filename => 'id_rsa_ssh', PP => 'ASCII', Armour => 1 ) or die $rsa->errstr(); delete $rsa->{KF}; $rsa->{PKF} = $KF; $public->write( Filename => sprintf('id_rsa_%s.pub',$kf) ); $rsa->{SKF} = $KF; $private->write( Filename => $priv_key_file ); } # --------------------------------------------------- # reading back the key ... $sk = new Crypt::RSA::Key::Private ( Filename => $priv_key_file, Identity => $Identity, ); #$sk->read( Filename => 'id_rsa_ssh.sec', Password => $Password ) +; $sk->hide(); $sk->write( Filename => 'id_rsa_hide.sec' ); $sk->reveal( Password => $Password ); $sk->write( Filename => 'id_rsa_reveal.sec' ); printf "sk: %s.\n",$sk->serialize(); # --------------------------------------------------- 1; # $Source: /my/perl/code/rsa_ssh_test.pl $;

so if I set $KF to 'Native' the script does work !

transcript

the error I get running the script (with $KF='SSH';) is presented below :

perl rsa_ssh_test.pl Number found where operator expected at (eval 6501) line 1, near "FORM +AT 1.1" (Do you need to predeclare FORMAT?) Can't use an undefined value as a HASH reference at /usr/local/share/p +erl/5.22.1/Crypt/RSA/Key/Private.pm line 217.