in reply to Re^2: Crypt::RSA Cant load private key
in thread Crypt::RSA Cant load private key

http://cpansearch.perl.org/src/PERLER/Crypt-OpenSSL-RSA-0.28/t/rsa.t shows several round trips

Replies are listed 'Best First'.
Re^4: Crypt::RSA Cant load private key
by ulisescastillo (Initiate) on Jan 10, 2012 at 00:40 UTC
    This is the result of executing the script you suggested:
    1..43 # Running under perl version 5.008008 for MSWin32 # Win32::BuildNumber 817 # Current time local: Mon Jan 9 18:36:07 2012 # Current time GMT: Tue Jan 10 00:36:07 2012 # Using Test.pm version 1.25 ok 1 ok 2 ok 3 ok 4 ok 5 ok 6 ok 7 ok 8 ok 9 ok 10 ok 11 ok 12 ok 13 ok 14 ok 15 ok 16 ok 17 ok 18 ok 19 ok 20 ok 21 Can't locate auto/Crypt/OpenSSL/RSA/is_private.al in @INC (@INC contai +ns: C:/Perl/lib C:/Perl/site/lib .) at Test.pl line 95

    But my actually my problem is to load the private key from a file, or if string (with openSSL, how do I?)

      I just looked at some of my code that successfully uses private keys (for signing). And found code like this:

      use File::Slurp qw(read_file); use MIME::Base64 qw(encode_base64); require Crypt::OpenSSL::RSA; my $key_text = read_file( $key_filename ); my $rsa_key = Crypt::OpenSSL::RSA->new_private_key($key_text); $rsa_key->use_pkcs1_padding(); my $bin_signature = $rsa_key->sign($plaintext); print encode_base64($bin_signature, '');
        Hi grantm, I tried your code and its the same problem
        message:
        RSA.xs:146: OpenSSL error: no start line at decryption.pl line 38.
        line 38 =
        my $rsa_key = Crypt::OpenSSL::RSA->new_private_key($key_text);
        It would be much to ask what version of module OpenSSL::RSA are you using?

        Does OpenSSL need that the --- BEGIN PRIVATE KEY --- headers be there? Im very sure those headers are there, because I've executed the command:

        $ openssl pkcs8 -inform DER -in pza000413788_1011171750s.key Enter Password:
        And I see the Headers:
        -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
        But what I ment is if should I have to change the format of the privateKey File or something. Any suggestion is really apreciated!

      This is the result of executing the script you suggested:

      Um, my suggestion was for you to read the script. Unlike the SYNOPSIS, the code is an actual working example of of usage, a complete round trip, from generating keys, to encrypting/decrypting. You'll notice there is no base64 function involved anywhere. You should not use any base64 functions.

        oh, yes, I read the script and tried to understand it, but didn't see anything that I could use, thats why I tried to executed it and see what happens, but I'll take another look more carefully, thanks!