Dan Ribe wrote:
Thanks Tom for the help.

It seems that there is some problem with the private key which I am passing.
With your key or newly generated key this logic works fine. Now the error
which I am getting is like :

OpenSSL error: error:0906D066:PEM routines:PEM_read_bio:bad end line

And last lines of my keys are like :

    "09dirkd+sRoXWShF8ctVVb4B1PAFTOBEa8diickehnAyEq6KhzLWpQqhqCnylETw\r\n"
    "Drys2uVaAzmRhS6tGJ2fdwPnlSLJrQbHuP938BkyxNhdYN8drfqb\r\n";

You appear to have an extra ";" here ---------------------------^
But that should give you a compilation error.

    "-----END RSA PRIVATE KEY-----\r\n";

I have seen that the key which you are using or which I have generated has
"==" at the end, the same is not true with my current private key (end lines
above).

Some have ==, some have =, some have nothing.  It depends on the exact
values.

Tom


I will try to get the new key from the concerned person. thanks

* PS : To my wonder this file is being read properlly using API
PEM_read_PrivateKey().

Then it should work.  Of course, you can't post the private key for us
to look at :-)

You could try modify your program to output your key string to a file
and compare the output file with the file that works to see if you have
something wrong with the actual text in the program.

Tom


thanks.



On Wed, Oct 1, 2008 at 10:22 PM, Kelly, Tom <[EMAIL PROTECTED]> wrote:

Hmmm.  Here's my example program (derived from yours).
Without the "\r\n" at the end of the lines, I get
the same error you do.  With the code as below,
it works fine:


$ cc -o readkey readkey.c -lcrypto
$ ./readkey
Success
$


#include <openssl/pem.h>
#include <string.h>

char *key =
"-----BEGIN RSA PRIVATE KEY-----\r\n"
"MIICXgIBAAKBgQCoxKMPX/VPz8ucSCyB2Z5LF4IeNnWW4qZqIylM71nwsNATdJP6\r\n"
"DKk3ehh6nNpX/qTQtE98se7qgV6PoUi6jP4qG0bxr1b5TqZ90c7JFi9u7uxU0NtY\r\n"
"ma/i+poWwoOnFIPi7qjgurTFxj6zEqxfiVV4iI+1qATqRSkyDOz0IacU7QIDAQAB\r\n"
"AoGAbI+YyHIUjdOACTbQEnMXBPzJQYAMohOHsuyNS6UHuPEz19/8tDNiwoHyrySo\r\n"
"u0PdZzcljnOy2PyBBGleLEo3z3iu03oW8yH+OVhmIQb40iBu7aIlYUG6Sv3y2rpD\r\n"
"07bRDCFrrJZ/YRyidKZfWOqCkz9ZCA43ijCcyxhjxPZw5GECQQDSgKIlsRWUbZqz\r\n"
"+Mor8/bzSuMkgC5Dus8T9bCZ938pQeXn+qoMJAjKQgP/4XeO8W0x3rgBRWjJUHkK\r\n"
"uUGbkztZAkEAzT7J9FogkYvS57h8mQHHapA9eSiRCKzEhO4OCf/Ou9hHKCQyZ+GY\r\n"
"sE0yrCR2U0ig1TYE/EhANYnweVutQ343tQJBALu59+EBUityq7rArxwPkDZcnMEa\r\n"
"hyfj23UDcSF+NStIF46QX0JAiI5H3WU/X+5cpHMLGrIXgmG2oJvNpxLldNECQQDI\r\n"
"X00wVbDIBvaOrGhPxBHYMhshpn35NxngILvp/Sfp8Vp+kN/41KCJNcSLlElEQ3po\r\n"
"zIUPesXcvt7ay6qaYqWlAkEAmErkFZ6bQQxUx11pE1qlm21qsu1kZY8PlJTmLzDp\r\n"
"Ir2/+KEp8Js9znwsefMOB4db9Eg0AMTVuAKLRf8fFup89A==\r\n"
"-----END RSA PRIVATE KEY-----\r\n";

int main(int argc, char **argv)
{
       ERR_load_crypto_strings();
       OpenSSL_add_all_algorithms();
       int keyLength = strlen(key);
       BIO *bio = BIO_new_mem_buf(key, keyLength);

       EVP_PKEY *pktmp = NULL;
       pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);

       if (pktmp == NULL) {
               char buffer[120];

               ERR_error_string(ERR_get_error(), buffer);
               fprintf(stderr, "OpenSSL error: %s", buffer);
       } else
               fprintf(stderr, "Success\n");
}

Tom



Dan Ribe wrote:

Tom,

Tried your suggestion, but it is not working !

Any other clues on this ?

Thanks much,
Dan

On Wed, Oct 1, 2008 at 7:04 PM, Kelly, Tom <[EMAIL PROTECTED]>
wrote:


Dan Ribe wrote:

 Hi,
I am trying to read the private key from the memory buffer (code snippet
below), But PEM_read_bio_PrivateKey() always returns an error : OpenSSL
error: error:0906D06C:PEM routines:PEM_read_bio:no start line

Can anyone please point out what I am doing wrong here. I am pretty new
to
OpenSSL, so please excuse me if i have messed up the things !

Code Snippet :

  char *key = "-----BEGIN RSA PRIVATE KEY-----"
  "jGK1T++C+Np4As+KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU"
  "N2AZVq28yjqt3RYaRPn0xhbmLfWH/o+wzlg58wIDAQABAoIBAAHEep7qWWMFWsbc"

 I think you need the "\n" at the end of each line (or possibly \r\n):
char *key = "-----BEGIN RSA PRIVATE KEY-----\n"
                                           ^
 "jGK1T++C+Np4As+KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU\n"
                                                                   ^
 "N2AZVq28yjqt3RYaRPn0xhbmLfWH/o+wzlg58wIDAQABAoIBAAHEep7qWWMFWsbc\n"
                                                                  ^

etc.

Tom
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]


 ______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to