Retrieving a public key from a private key in OpenSSL

I need to extract the RSA public key from the RSA private key using OpenSSL.

I am currently using RSAPublicKey_dup() , passing the RSA* private key to get the public key. However, although the call seems to work, I cannot load (or use) this public key using the openssl command-line tool.

If I create a public key using the command line tool (" $ openssl rsa -in private.pem -pubout > public.pem "), I can use it and it works like a charm.

Do you guys know how I can get this job? Maybe another feature? The OpenSSL documentation is pretty hard to browse ...

Thanks.

+4
source share
1 answer

I was able to do this job with PEM_write_bio_RSA_PUBKEY() to write PEM data to a memory buffer in memory, and then using PEM_read_bio_RSA_PUBKEY() to get a new RSA* .

Now you can use the generated public key;)

+2
source

Source: https://habr.com/ru/post/1306564/


All Articles