I need to go over this again, I need an implementation which will also encode arbitrary buffers, not just null-terminated strings, also base64_decode currently doesn't restore the correct buffer length.