How to find size of decoded base64 data in C

I have a function that decodes base64 encoded data into binary data, but I don't know how to find the length of the decoded data. I am using BIO functions in openssl.

unsigned char *unbase64(unsigned char *input, int length)
{
    BIO *b64, *bmem;

    unsigned char *buffer = (unsigned char *)malloc(length);
    memset(buffer, 0, length);

    b64 = BIO_new(BIO_f_base64());
    bmem = BIO_new_mem_buf(input, length);
    bmem = BIO_push(b64, bmem);

    BIO_read(bmem, buffer, length);

    BIO_free_all(bmem);

    return buffer;
}

      

+1


source to share


1 answer


BIO_read will return the number of bytes read. Anyway, you should be checking return values.



+3


source







All Articles