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

Now getting this error
RSA.xs:146: OpenSSL error: no start line at decryption.pl 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?

Replies are listed 'Best First'.
Re^3: Crypt::RSA Cant load private key
by Anonymous Monk on Jan 09, 2012 at 23:07 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, '');

        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.