Hi Trung,
 The error which u got was you can not read the public key as in the
certificate it is not finding the lines as "BEGIN RSA CERTIFICATE"
so here i am giving you the code , use it directly , it will work fine as i
refined it many times ... and one more thing is error string funtion will
give you the reason also , so it is human readible message only...



pubk = RSA_new();
if(pubk == NULL)
printf("error to create new RSA structure \n");

fp = fopen (recevercert, "r");
if (fp == NULL){
pri ntf("err ");
exit (1);
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
fclose (fp);


if (x509 == NULL) {
printf("error reading the certificate \n");
ERR_print_errors_fp (stderr);
exit (1);
}

pub=X509_get_pubkey(x509);
if (pub == NULL) {
printf("error reading the public key \n");
ERR_print_errors_fp (stderr);
exit (1);
}

pubk = EVP_PKEY_get1_RSA(pub);


On 4/13/08, ThĂ nh Trung Nguy&#7877;n <[EMAIL PROTECTED]> wrote:
>
> Hi !
>
> I used PEM_write_RSAPrivateKey() to write private key to a pem file.
> Then I used PEM_read_RSAPublicKey() to read public key from that file, but
> it returned an error.
> The ERR_error_string() only return message like :
>     error:0906D06C:lib(9):func(109):reason(108)
> So can any one tell me can i use PEM_read_RSAPublicKey() to load public
> key from a private key ?
> And are the any way to get human understandable error message ?
>
> Thanks !
>
>
> trungnt
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



-- 
--Best Regards
Shankar

Reply via email to