BIO_f_base64

Don't forget to BIO_flush() a memory BIO in OpenSSL if you're using a BIO chain (via BIO_push() and BIO_pop()) and write a small amount of data to the BIO!

Otherwise, if you're like me, you'll keep wondering why no data has been written to the bottom BIO.

Also, you should really call

BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL)

to make sure that the base64 BIO *b64 doesn't add (or expect) a newline at the end of each encoded chunk