Hi All, I figured out my problem. The call to BIO_set_flags() wasn't correct. Replacing the sequence:
: b64 = BIO_new(BIO_f_base64()); BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL); bio = BIO_push(b64, bmem); : with : b64 = BIO_new(BIO_f_base64()); bio = BIO_push(b64, bmem); BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); : fixed the problem. Regards, ...doug --- On Thu, 5/20/10, Doug Kehn <rdk...@yahoo.com> wrote: > From: Doug Kehn <rdk...@yahoo.com> > Subject: Re: Base64 Decode Problem/Question > To: openssl-users@openssl.org > Date: Thursday, May 20, 2010, 3:37 PM > Hi Bruno, > > --- On Thu, 5/20/10, Bruno Vetel <bruno.ve...@esas.fr> > wrote: > > > From: Bruno Vetel <bruno.ve...@esas.fr> > > Subject: Re: Base64 Decode Problem/Question > > To: openssl-users@openssl.org > > Date: Thursday, May 20, 2010, 1:43 PM > > Doug Kehn <rdk...@yahoo.com> > > writes: > > > > > Hi All, > > > > > Hi > > > > \n is not base64. Try with echo -n > > > > I removed the '\n' and got the same result. > > > (Sorry for the double post. I had mailer problems and > didn't think the first attempt went out.) > > > > > > I'm trying to decode a base64 encoded string. > > The problem I'm running in to is that BIO_read() > always > > returns 0. BIO_should_retry() and BIO_should_read() > > also return 0 when BIO_read() returns 0. If the > base64 > > encoded string is shortened, BIO_read returns the > decoded > > information. I'm using OpenSSL 0.9.8g 19 Oct 2007 > on > > Ubuntu 9.04. > > > > > > Any suggestions on what I'm doing wrong? > > > > > > Thanks, > > > ...doug > > > > > > ---8<----- > > > > > > /* > > > * Compiled with: gcc -Wall -lssl > > > */ > > > > > > #include <openssl/bio.h> > > > #include <openssl/evp.h> > > > #include <stdio.h> > > > #include <string.h> > > > > > > int main(int argc, char **argv) > > > { > > > #if 1 > > > /* > > > * This does not work > > > */ > > > char *message = > > > "Tm8gaXMgdGhlIHRpbWUgZm9yIGFsbCBnb29kIG1lbiB0byBjb21lIHRvIHRoZSBhaWQgb2YgdGhlaXIgY291bnRyeS4NClRoZSBxdWljayBicm93biBmb3gganVtcGVkIG92ZXIgdGhlIGxhenkgZG9nJ3MgYmFjayAwMTIzNDU2Nzg5Lg==\n"; > > > #endif > > > #if 0 > > > /* > > > * This shortened version > > works > > > */ > > > char *message = > > "Tm8gaXMgdGhlIHRpbWUgZm9yIGFsbCBnb29kIG1lbiB0by==\n"; > > > #endif > > > > > > BIO *b64, *bio, *bmem; > > > char *buf; > > > int i = strlen(message) + 25; > > > > > > buf = malloc(i); > > > if (!buf) { > > > printf("malloc > > fail, %m\n"); > > > return -1; > > > } > > > > > > bmem = > > BIO_new_mem_buf((void*)message, -1); > > > b64 = BIO_new(BIO_f_base64()); > > > BIO_set_flags(bmem, > > BIO_FLAGS_BASE64_NO_NL); > > > bio = BIO_push(b64, bmem); > > > i = BIO_read(bio, (void*)buf, i); > > > buf[i] = '\0'; > > > BIO_free_all(bio); > > > > > > printf("%s\n%s\n", message, buf); > > > > > > return 0; > > > } > > > > > > > > > > > > ______________________________________________________________________ > > > OpenSSL Project > > > > http://www.openssl.org > > > User Support Mailing List > > openssl-users@openssl.org > > > Automated List Manager > > > > majord...@openssl.org > > > ______________________________________________________________________ > > OpenSSL Project > > > > http://www.openssl.org > > User Support Mailing List > > openssl-users@openssl.org > > Automated List Manager > > > > majord...@openssl.org > > > > > > ______________________________________________________________________ > OpenSSL Project > > http://www.openssl.org > User Support Mailing List > openssl-users@openssl.org > Automated List Manager > > majord...@openssl.org > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org