I have been scouring the web to find information on the proper use (or
using the correct functions available) of the BIO_* family of functions.
What I am attempting to do is to simply return a public key as a string.
Currently I am performing a series of operations to accomplish this like so:
EVP_PKEY *pkey = NULL;
NETSCAPE_SPKI *spki = NULL;
BIO *out = BIO_new(BIO_s_mem());
BUF_MEM *bio_buf;
char *s = NULL;
spki = NETSCAPE_SPKI_b64_decode(spkac, strlen(spkac));
pkey = X509_PUBKEY_get(spki->spkac->pubkey);
BIO_write_bio_PUBKEY(out, pkey);
BIO_get_mem_ptr(out, &bio_buf);
s = emalloc(bio_buf->length);
BIO_READ(out, s, bio_buf->length);
The contents of 's' do indeed contain the public key as expected.
However it seems to be reading past the specified length and returning
some trailing bits as shown below:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuQ5gHAFoCkDl7po4ORPk
znvwQeadnz60aIN/t3M/YeAyMiVMXICgA6UW3nHpUTaXhWrH+kd1Feep/UBj+2Rm
WV4fUZv3nabc9uPG9+Bfbf1oDwo5fZETjn0bpVt2WY3eWDUzHI4o6lmBqK+a4DnI
3s9IJxV2ItFlkj6E2znUvJFC9uBdDXmti0mzc346qiesfaK0Ep//Zwu3Wijm97X+
SLroWG7q/0cLAEagWhISlfK16QeNZqL2cRp0PA/NoSchMj7sxt6+oldrJOTTBQ9N
5do29jWdXZb8QqF5uJGmSfZEICbzDAApFeyOHt6AfZBkBNuhpdjQMGaepb/sLqem
1wIDAQAB
-----END PUBLIC KEY-----
z�
I am I using the wrong macro or function when attempting this operation?
Any tips, pointers etc is appreciated.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager majord...@openssl.org