> Hi,
>
> I generated a x509 certificate. When I try to read the private key with
> PEM_read_PrivateKey I always get NULL as return value and when calling
> perror I get an Illegal seek.
>
> Here is my code:
>
>       FILE *pemKeyFile;
>       EVP_PKEY *privKey;
>
>       pemKeyFile = fopen ("/home/user/testkey.pem", "r");
>       if (pemKeyFile == NULL) {
>               perror ("open key file");
>               return 7;
>       }
>       // reading private key in PEM format
>       privKey = PEM_read_PrivateKey (pemKeyFile,
>               NULL,
>               NULL,
>               NULL );
>       if (privKey==NULL){
>               perror("read");
>               return 6;
>       }
>       if (EVP_PKEY_type(privKey->type)==EVP_PKEY_RSA){
>               printf ("Key type is: %d this means RSA\n",privKey->type);
>       }
>       else {
>               printf ("NO RSA :(\n");
>       }
>
> Can anyone tell me why this does not work ?

Most likely the file you're reading doesn't contain a private key in a
format that PEM_read_PriveKey likes. But the best way to tell is to use more
sensible error output code. For example, call ERR_print_errors_fp(stderr).
The 'perror' function will only work if the error was an error in a system
call. Most likely, the error was detected in the SSL code that tried to
process the data in the file.

DS


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

Reply via email to