0

I am able to retrieve the public key contents from a cert file using openssl by following the link http://fm4dd.com/openssl/certpubkey.htm

However, it prints the public key to stdout. I want to be able to store it in a string . Is there a way to get it into a char buffer or a string ?

The line PEM_write_bio_PUBKEY(outbio, pkey) prints to stdout.

Searched quite a bit, wasnt able to get what I wanted.

Any help will be appreciated, better if the code sample is provided as I'm running out of time.

Thanks in advance.

2
  • The code you link to sets up outbio to be stdout. I'd guess you just need to make a different output BIO instead? e.g. BIO_s_mem Commented Nov 16, 2018 at 17:05
  • Thanks, if you could provide some code to do that, would be helpful. Commented Nov 16, 2018 at 17:09

1 Answer 1

2

I found a solution finally ! X509 structure to human readable string

Just replaced with EVP_PKEY *key in X509_to_PEM() signature and used PEM_write_bio_PUBKEY(bio, key) instead of PEM_write_bio_X509(bio, cert).

Worked !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.