Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2018-06-23 20:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?



      Results (125 votes). Check out past polls.

      Notices?