Below is the code I
am using to try and test the base64 encode in openssl. I am using rand to
generate a binary and then encoding that to base64. Instead of using a file, I
want to use memory to output the base64 encoded buffer. This code compiles and
runs, but my output buffer is all 0. Any help would be appreciated. What have I
missed?
The variable written
does show 16 like it should......help!
#include <iostream>
#include <memory.h>
#include "evp.h"
#include "rand.h"
#include "bio.h"
#include <memory.h>
#include "evp.h"
#include "rand.h"
#include "bio.h"
using namespace std;
int main()
{
BIO *b64;
unsigned char *pbuffer = new unsigned char [16];
unsigned char *pOutput = new unsigned char [100];
int written;
{
BIO *b64;
unsigned char *pbuffer = new unsigned char [16];
unsigned char *pOutput = new unsigned char [100];
int written;
memset(pOutput, '0',
100);
RAND_bytes(pbuffer, 16);
b64 = BIO_new(BIO_f_base64());
written = BIO_write(b64, pbuffer, 16);
RAND_bytes(pbuffer, 16);
b64 = BIO_new(BIO_f_base64());
written = BIO_write(b64, pbuffer, 16);
cout << written <<
endl;
BIO_get_mem_ptr(b64, pOutput);
for ( int nLoop = 0; nLoop< 16;
nLoop++)
{
cout << pOutput[nLoop];
}
cout << "\n" << endl;
{
cout << pOutput[nLoop];
}
cout << "\n" << endl;
BIO_free_all(b64);