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

Dear Monks,
I've written (copied) the following program:
#! /usr/bin/perl use warnings; use Crypt::RSA ; my $rsa = new Crypt::RSA; my ($public, $private) = $rsa->keygen ( Identity => 'Luca Da Luca <luca@daLuca.com> ', Size => 512, Password => 'A day so foul & fair', Verbosity => 1, ) or die $rsa->errstr(); $public->write(Filename => 'rsa.public' ); $private->write(Filename => 'rsa.private' ); $public = new Crypt::RSA::Key::Public ( Filename => 'rsa.public'); $private = new Crypt::RSA::Key::Private( Filename => 'rsa.private' ) +; $message = "Hallo allemaal :)) \n" ; my $cyphertext = $rsa->encrypt ( Message => $message, Key => $public, Armour => 1, ) || die $rsa->errstr(); my $plaintext = $rsa->decrypt ( Cyphertext => $cyphertext, Key => $private, Armour => 1, ) || die $rsa->errstr(); print "text: $plaintext\n" ;
When I execute this I get the following message: n is not a number.
Any suggestion why n is not a number but most of all, how to fix this ???
Furthermore I noticed that when I only write the keys to file I get the same message

Thanks in advance
Luca

Replies are listed 'Best First'.
Re: Crypt::RSA problem
by graff (Chancellor) on Sep 26, 2005 at 12:55 UTC
    Are you sure the module was installed properly? This would include correct installation of Math::Pari, which in turn depends on installation of an external compiled library called "pari".

    The module installation should have included some tests, and it is possible to "force" installation despite test failures. If that's what happened in your case, you'll need to try the installation again, and pay attention to the failures.

      But if I create the keys and use them directly (no writing to and reading from file) it all works fine.
      Maybe this is interesting: If I print the key before writing I get the following:
      key=Password valu=A day so foul & fair key=Version valu=1.91 key=Checked valu=0 key=Identity valu=Lord Macbeth <macbeth@glamis.com> ..... key=_phi=> 7210735926686440535829990956186709974464809186521836 +355832311976096790529618024634910931659740003773771843595827999358462 +719066220022694321619622387401960 ..... key=_n=> 721073592668644053582999095618670997446480918652183635 +583231197609679052961819700359005877557710889766589552041195848079762 +1578108309291796942263931673339 ..... key=_q=> 100915410784627151408499821928866674137454562910056455 +419204814119795206900509 ..... key=_u=> 714532683424886856966240721230579098216677719924554328 +67392661202846337370871 ..... key=_dp=> 55244914096508209456284400117059592742268460981246650 +212332286378244672760967 ..... key=_dq=> 36302843828674577225696808359880055897158426599215535 +471345551979357835961943 ..... key=_d=> 880471060418539224794851735339212418508575599615030917 +0194136550910004929385 ..... key=_e=> 641184135470923308460913000233054168594704091053521728 +905021305093331347031478407043455534130351495979870847598261273194948 +5272487877726082773168046267553 ..... key=_p=> 65537 key=Cipher valu=Blowfish
      If I print the code after writing it to file (so I haven't red it yet!):
      key=Version valu=1.91 key=Checked valu=0 key=Identity valu=Lord Macbeth <macbeth@glamis.com> key=private_encrypted valu=Tie::EncryptedHash=HASH(0x8451cb0) key=Cipher valu=Blowfish


      Luca
        If I remove Password from the keygen everything works fine !! How do I write and read a key using a password ?

        Oooh I fixed it, it is simple:$private = new Crypt::RSA::Key::Private( Filename => 'rsa.private', Password => 'A day so foul & fair' ); Luca