开发者

Extracting public key from private key in OpenSSL

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

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

If I generate the 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 work ? Maybe another function ? The OpenSSL documentation is quite 开发者_高级运维hard to browse...

Thank you.


I managed to make this work using PEM_write_bio_RSA_PUBKEY() to write the PEM data to a in-memory buffer, then using PEM_read_bio_RSA_PUBKEY() to get a new RSA*.

Now the generated public key can be used ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜