Neil Dugan wrote:

Dr. Stephen Henson wrote:
On Mon, Jul 27, 2009, Neil Dugan wrote:

Hi,

I have been trying to read the keys generated by "openssl genrsa ..." and "openssl rsa -pubout ..." commands.

I successfully (according to the return code) read the private key with

if (in = BIO_new_file("rsakey.pem", "r")) {
    int ok;
    printf ("Created private BIO\n");
    ok = (PEM_read_bio_RSAPrivateKey(in, &rsa, NULL, NULL) != NULL);
    printf ("ok = %s\n", (ok != 0) ? "true":"false");
    BIO_free(in);
}

but the similar code using PEM_read_bio_RSAPublicKey() doesn't want to work.


Use PEM_read_bio_RSA_PUBKEY() instead.

Steve.

Thanks that seemed to work.
But the "PEM_write_RSAPublicKey(stdout, rsa);" call doesn't output the same data as what is in the key file. So did it get read properly?

I found that "PEM_write_RSA_PUBKEY(stdout, rsa);" does print the correct key.

Why the two very similar functions? and why aren't they outputing the same data?

Now I have updated the code, to try and encrypt/decrypt some test data. Why is it causing a segmentation fault at line 39 the "RSA_private_decrypt(size, from, to, rsa, RSA_NO_PADDING);" call?



______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to