I am a newbie to OpenSSL and wondering if
anyone can help me. 

I am trying to use BIO_f_base64 but it does not
work for instance in the following code. 
The second BIO_read, which is supposed to decode
the base64 encoded string, always returns nothing,
or "".

Am I doing something wrong?

Thanks a lot in advance. 

Yoshi


#include <openssl/bio.h> 
#include <openssl/evp.h> 

int main()
{
    BIO *bio, *b64, *mem, *bio2, *b64_2;
    char msg[]= "Hello World!\n";
    char buf[256];
    char buf2[256];
    int i;
    
    memset(buf, 0, sizeof(buf));
    memset(buf2, 0, sizeof(buf2));
    
    mem = BIO_new(BIO_s_mem());
    b64 = BIO_new(BIO_f_base64());
    b64_2 = BIO_new(BIO_f_base64());
    
    bio = BIO_push(b64, mem);  //connect the b64 filer to the chaine

    BIO_write(bio, msg, strlen(msg));//encoding writing to the chain
    BIO_flush(bio);

    i = BIO_read(mem, buf, sizeof(buf));//read the base64 encoded data
    BIO_write(bio2, buf, i); //then write the data to buf
        
    bio2 = BIO_push(b64_2, bio2);//connect the b64 filter for decoding

    i = BIO_read(bio2, buf2, sizeof(buf2));
                             //decoding reading from the bio2 chain

    BIO_flush(bio2);
    
    printf("buf=%s\n",buf);
    printf("buf2=%s\n",buf2);
    
    BIO_free_all(bio);
    BIO_free_all(bio2);
    
    return 0;
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to