将未签名的char数组转换为base64字符串

Convert unsigned char array to base64 string

本文关键字:转换 base64 字符串 数组 char      更新时间:2023-10-16

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

我从ActiveX控件中获得数组,我想使用JavaScript在网页中显示它,因此我必须将其转换为" Base64 String",因此我的问题是

如何将未签名的char数组转换为C 中的base64字符串?

苹果已经发布了开源base64编码/解码器。我记得在Windows项目上没有任何问题的编译。来源。标题在这里。

例如:

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