Hi,
I'm trying to read a base64 encoded msg from an in memory buffer and decode
it (and possible write to a file or to mem)
I can't figure out what's wrong with the code snippet below.
From what I have read in the openssl book and other docs, looks like this is
how it should be done (see code snippet below).
The problem is BIO_read(b64, msg, 512) always retuns zero. but if i do
BIO_read(bio, msg, 512)
everything works. Which tells me that the b64 isn't working or hasn't been
configured/attached to bio correctly.
I want b64----bio. isn't this the way to set the chain correctly
BIO_push(b64, bio);
Can someone please point out where i'm going wrong.
Thanks in advance for you comments.
// reads b64 encoded msg (pReadBuffer) and writes to pWriiteFile.
void decode(char *pReadBuffer, int pLength, char *pWriteFile)
{
char msg[512];
int readbytes = -1;
printf("buffer write file %s\n", pWriteFile);
// the decode msg is written to this bio
BIO *fileWrBIO = BIO_new_file(pWriteFile, "w");
BIO *b64 = BIO_new(BIO_f_base64());
BIO *bio = BIO_new_mem_buf(pReadBuffer, pLength);
BIO_push(b64, bio);
while ((readbytes = BIO_read(b64, msg, 512)) > 0)
{
BIO_write(fileWrBIO, msg, readbytes);
BIO_flush(fileWrBIO);
memset(msg, 0x00, sizeof(msg));
printf("while bytes read %d\n", readbytes);
}
printf("bytes read %d\n", readbytes);
BIO_free_all(bio);
BIO_free_all(fileWrBIO);
}
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager [EMAIL PROTECTED]