Hi Mike, Thanks for your postings in reply to my base64 decoding problem. I must admit that I saw your first posting only after sending out the reply to William, so let's correct that here :-)
In your last posting you wrote: > Are you stripping the bytes that might appear in the stream > that do not represent encoded characters or a part of the count? That's an interesting thought. I assumed that when BIO_f_base64 decodes it is expecting the information it has originally encoded. The man-page states: BIO_f_base64() returns the base64 BIO method. This is a filter BIO that base64 encodes any data written through it and decodes any data read through it. So, f_base64 writes a newline after 64 encoded chars. When I remove the newline chars following your suggestion I get no output at all. Maybe that's kind of weird too, but at least it matches my assumtion that the way base64 writes information is the way it expects it back. But your remark did put me onto some useful track: base64's output suggests that its output should be read in chunks of 64 bytes. OK so far, but when I do that repeatedly on the same base64 and mem object conversion fails after one or two blocks. The following code, however, works fine: int main() { while (true) { char inbuf[65]; BIO *b64 = BIO_new(BIO_f_base64()); BIO *mem = BIO_new(BIO_s_mem()); BIO *bio = BIO_push(b64, mem); int inlen; if ((inlen = fread(inbuf, 1, 65, stdin)) <= 0) break; BIO_write(mem, inbuf, inlen); inlen = BIO_read(bio, inbuf, 48); if (inlen > 0) fwrite(inbuf, inlen, 1, stderr); BIO_free_all(bio); } } Note that I renew f_base64 and s_mem at each new block of 65 bytes. Here I use `65' and `48', but you could multiply these values by any integral factor `x', e.g., using x = 15 and then x * 65 and x * 48. The program works fine for any positive x. The main problems I have with the above code (irrespective of the factor used) is that I have to renew the f_base64 and s_mem objects at each new read-cycle and that I dislike magic numbers. I'm willing to accept the latter, considering that `x * 65' and `x * 48' are inherent elements of the base64 decoding, but I would be very interested in knowing how to re-use rather than re-new the f_base64 and s_mem objects. > > ... there must be a more > > systematic way to handle my problem.... > > There is, I posted the link to one such solution. Have you read it? Yes, by now I have. It doesn't solve the problem though: the posted solution `hand-decodes' base64 encoded information instead of using the ssl-functions. I'm sure I can do that, too, but my original plan was (and still is) to use the available ssl-functions for that. Thanks for showing me the link, though. I appreciate it, but completely missed your posting when writing my previous posting. > Is this a homework assignment? :-) Great remark! No it isn't. One day I could make it into an assignment for my students, though ;-) But no: for now I'm just interested in applying the facilities offered by the openssl library to my own programs. BTW: It's highly unlikely that I'll be able to reply to any new postings to this thread for the coming 3 weeks. Please don't take silence from me during that period for impoliteness or lack of interest. Cheers, -- Frank B. Brokken Center for Information Technology, University of Groningen (+31) 50 363 9281 Public PGP key: http://pgp.surfnet.nl Key Fingerprint: 8E36 9FC4 1DAA FCDF 1A0D B19F DAC4 BE50 38C6 6170 ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org