views:

44

answers:

1

Hi All, I've created an RSA key using:

RSA_generate_key(2048, RSA_F4, NULL, NULL);

Now I want to export the public key to another party B. Right now, I've just memcpy'd the entire RSA* struct and sent that over the wire, and B is able to use that to encrypt using RSA_public_encrypt().

But I think in this case I've actually exported the entire public/private key pair, and not just the public key. I want to only export the public component of the RSA key. How do I use OpenSSL APIs to do that?

Thanks

+2  A: 

You probably want the functions d2i_RSAPublicKey and i2d_RSAPublicKey. i2d serializes a RSA key struct to a bytestring, and d2i does the reverse operation.

Jack Lloyd
that's exactly what I needed, thanks a lot!
mindthief