I've been able to encode a std::vector<char>
to Base64 using boost and the following code:
using namespace boost::archive::iterators;
std::string message(binary.begin(), binary.end());
std::stringstream os;
using base64_text = insert_linebreaks<base64_from_binary<transform_width<const char *, 6, 8>>, 72>;
std::copy(
base64_text(message.c_str()),
base64_text(message.c_str() + message.size()),
ostream_iterator<char>(os)
);
return os.str();
I found this on Stackoverflow. Well, now I want to to the same thing backwards, putting in a Base64 formatted std::string
and end up with a std::vector<char>
. But I can't adapt my example to do the thing in reverse. I found some other code online, which works nice with a Hello World example, but when there's an actual bigger Base64 which also contains some critical characters like backslashes, the whole thing crashes.
This is what I'm doing now to decode:
using namespace std;
using namespace boost::archive::iterators;
typedef
transform_width<
binary_from_base64<string::const_iterator>, 8, 6
> binary_t;
string dec(binary_t(str.begin()), binary_t(str.end()));
return dec;
It crashes in the last line before the return, when I'm about to create the string. Do you see what's wrong with it?