In the base64_encode function the param is a string
and you determine the length with
(from the source:)
unsigned char *base64_encode(const unsigned char *string) {
const unsigned char *current = string;
int length = strlen(string);
If you use real binary data the length is wrong if
there is a 0x00 char somewhere in the data.
Regards
Helmut Franzke