How to export public key in OpenSSL / libcrypto?

I created an RSA key using:

RSA_generate_key(2048, RSA_F4, NULL, NULL); 

Now I want to export the public key to the other side of B. Right now, I just memcpy'd the entire RSA * structure and sent it over the wire, and B can use this for encryption using RSA_public_encrypt ().

But I think that in this case I actually exported the whole pair of public / private key, not just the public key. I only want to export the public component of the RSA key. How can I use the OpenSSL API for this?

thanks

+4
source share
1 answer

You probably need the d2i_RSAPublicKey and i2d_RSAPublicKey . i2d serializes the RSA key structure for the byte sequence, and d2i performs the inverse operation.

+6
source

All Articles