将unsigned char数组转换为base64字符串

时间:2016-12-29 10:48:52

标签: javascript c++ activex

我有一个代表图像的unsigned char数组,我想在网页中显示它。

我从ActiveX Control获取数组,我想在我的网页中使用JavaScript显示它,所以我必须将其转换为“base64 string”,所以我的问题是

如何在c ++中将unsigned char数组转换为base64字符串?

1 个答案:

答案 0 :(得分:1)

Apple发布了一个开源Base64编码/解码器。我记得曾经在Windows项目中编译没有问题。来源here。标题here

例如:

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
相关问题