Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Crypt::RSA w/ KF = 'SSH' (how to read back keys ?)

by iglake (Initiate)
on Feb 09, 2018 at 10:01 UTC ( #1208799=perlquestion: print w/replies, xml ) Need Help??
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1208799]
Approved by marto
help
Chatterbox?
NodeReaper sorts his collection of toe tags, alphabetically

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-02-18 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (253 votes). Check out past polls.

    Notices?