0

I have an unsigned char array that represent an image, and I want to show it in a web page.

I get the array from ActiveX Control, and I want to show it in my web page using JavaScript, so I have to convert it to "base64 string", so my question is

how to convert unsigned char array to base64 string in c++?

Mohammad Shaban
  • 176
  • 1
  • 16
  • 1
    Check out http://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c – pSoLT Dec 29 '16 at 10:50

1 Answers1

2

Apple has published an open source Base64 encode/decoder. I recall having this compile with no issue on a Windows project once. Source here. Header here.

For example:

unsigned char* array = <your data>;
int len = <number of bytes in "array">

int max_encoded_length = Base64encode_len(len);
char* encoded = new char[max_encoded_length];

int result = Base64encode(encoded, (const char *)array, len);

// encoded is now a null terminated b64 string
// "result" is the length of the string *including* the null terminator
// don't forget to invoke "delete [] encoded" when done
selbie
  • 100,020
  • 15
  • 103
  • 173