Hi,

I am trying to create RSA public and private keys on Windows with
OpenSSL 0.9.7e. I want to save both to disk for later use, but I can't
figure out how to read them again...

I am doing the following:

############ CUT ############
<code to seed the pool>

rsa = RSA_generate_key(RSA_KEY_LENGTH, RSA_F4, NULL, (char *)stdout);

< put rsa into a buffer p>

pub_rsa = d2i_RSAPublicKey(NULL, (const unsigned char**) &p, (long)len);
len -= (p-buf);
priv_rsa = d2i_RSAPrivateKey(NULL, (const unsigned char**)&p,(long)len);

<error handling>

// save public key
BIO *pub = BIO_new_file(pubkey_file, "w");
PEM_write_bio_RSAPublicKey(pub, pub_rsa); 
BIO_free(pub);

// save private key
BIO *priv = BIO_new_file(privkey_file, "w+");
PEM_write_bio_RSAPrivateKey(priv, priv_rsa, NULL, NULL, 0, NULL, NULL); 

// load saved private key and write it to a new file for comparison
RSA *r_rsa;
BIO *tmp = BIO_new_file("privkey.txt", "w");
BIO_reset(priv);
PEM_read_bio_RSAPrivateKey(priv, &r_rsa, NULL, NULL);
BIO_free(priv);
PEM_write_bio_RSAPrivateKey(tmp, r_rsa, NULL, NULL, 0, NULL, NULL); 

############ CUT ############

My idea was to compare the "privkey_file" with "privkey.txt" and verify
that they are identical. 

I am unfortunately getting an access violation in the call to
PEM_read_bio_RSAPrivateKey() in libeay32.dll. I must be doing something
wrong...

How should I go about reading those keys from disk?

Thanks a lot in advance,
  jules


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

Reply via email to