Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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 <>'; 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('',$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/ $;

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


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

perl 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/ line 217.

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

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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2018-12-17 02:14 GMT
    Find Nodes?
      Voting Booth?
      How many stories does it take before you've heard them all?

      Results (71 votes). Check out past polls.

      • (Sep 10, 2018 at 18:53 UTC) Welcome new users!