Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Crypt::RSA Cant load private key

by ulisescastillo (Initiate)
on Jan 09, 2012 at 18:28 UTC ( #947048=perlquestion: print w/replies, xml ) Need Help??

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

Hi Masters,

I'm using ActivePerl v5.8.8 and downloaded the modules I need which are

use Crypt::OpenSSL::RSA; [v 0.22] OR Crypt::RSA [v 1.57] use XML::XSLT; use XML::LibXML;

Describing Active Repository 2: Name: perl5.8modules
Type: Webpage

Because in newest perls I can't install them

But now I'm having a problem trying to load a privateKey to sign a file, with openSSL I have the error:
RSA.xs:146: OpenSSL error: no start line at line 40.

$keyFile = shift; $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($keyFile);

And when Trying this:

$keyFile = shift; $key = new Crypt::RSA::Key::Private ( Filename => $keyFile }

The error message is:
Can't use an undefined value as a HASH reference at C:/Perl/site/lib/Crypt/RSA/Key/ line 220.
Any Suggestion??

---> UPDATE <---
If I give to OpenSSL::RSA the result of executing this command in linux:
$ openssl pkcs8 -inform DER -in aaqm610917qja_1011180955s.key Enter Password: -----BEGIN RSA PRIVATE KEY----- MIICWwIBAAKBgQCcphXGAbrbUnaumkSTsbGrFIfkaajOpvP1RFcVcbpWe7JBNXAw ShKIH79QGLYEc9ATBmlxtjAma0B4ZRBTjmQ4vQrp9LwT3bCNX+9J9lUOHGsCysya u3VxGNoCbhBxMYQP835LjAcy1d4AScOjGx8hxTZ6AUXtMmyEe+0NNQsJnQIDAQAB AoGAF4PfFOBBmpbgdgl2be1ozFPCqokp7Aun55OgtvlhjYX4Fk3dT4JvEbwiTfXH rRdtjs2Rmp5M0Bedj/Ur5D8l0BqBQznSrm6JGaDMv40wOk265qoECda/zZ2tdjvU xmcYpuu2AE4mdvqVsMqDOVCSp/5aBUL+hv54OtADuVi/J0ECQQDIa1DW9ct2FsQT h6sNdvgjI35fJ/MKA0y/kLD0wbwHT1VbUE3GevHHSeYOccKnWErlw4ppt9jglEvt m/n1BlOlAkEAyBdN4sKUxbTy1NobPgQJ2UsmaCNU7JN9+wIgJ8gePkRktsHLE+ec yBhBki3rYvexbXlmOU94yfrzzPZuyBkcmQJAfAr/o6vJW7NHdBb55YGGnqjvJBHj uITGUaJKA5KMv7F4UOXo3Tlmv0ObocEDCvP4lzBpUHk7P/RI8i0hjWd3CQJAal0p A//XwflclJWUobTX33C5a+ZMQK5u673Hhh41JXiJ6TS/VUdr6loqkSBj3mo5IS7F jnWWihgi/bOKVEg1EQJACsF3shzuBETh5dyoqBJRP7EbzxB8SaeQapa9lJlkrOKD HAwVS32OtPWCmU3isOjbqh+Mc3fNRe0Y9xq+nsingg== -----END RSA PRIVATE KEY-----
I can load the private key, so now I need a way to get this openSSL pkcs8 convertion from DER to PEM with perl

Replies are listed 'Best First'.
Re: Crypt::RSA Cant load private key
by toolic (Bishop) on Jan 09, 2012 at 18:35 UTC
    It looks like you have a typo (use strict and warnings):
    $keyFile = shift; $key = new Crypt::RSA::Key::Private ( Filename => $keyFilkeyFile }
    $keyFile = shift; $key = new Crypt::RSA::Key::Private ( Filename => $keyFile }
      Now getting this error
      RSA.xs:146: OpenSSL error: no start line at line 40.
      when trying:
      $stringKey = encode_base64(readKey($keyFIle)); $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($stringKey); sub readKey{ $llave = shift; open (FILE, $llave); binmode(FILE); while (read(FILE, $buff, 1024)) { #4)) { $key.= $buff; } close FILE; return $key; }
      I use encode_base64 because Crypt::OpenSSL::RSA->new_private_key needs a string, or what is the correct way to do this?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://947048]
Approved by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-05-18 11:03 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (178 votes). Check out past polls.