Based on this code here, I was able to write some code that converts a vector of integers into a base64 encoded version. And I can confirm it is the right output by comparing with a separate Java implementation.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <cstdint>
#include <typeinfo>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#include <boost/archive/iterators/remove_whitespace.hpp>
///....
using namespace std;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
namespace bi = boost::archive::iterators;
std::stringstream os;
typedef
bi::base64_from_binary< // convert binary values to base64 characters
bi::transform_width< // retrieve 6 bit integers from a sequence of 32 bit ints
vector<int32_t>::const_iterator,
6,
32
>
>
base64_text;
copy(
base64_text(di.cbegin()),
base64_text(di.cend()),
ostream_iterator<char>(os)
);
cout << os.str() << "\n";
Now I'm trying to write the code to decode this back into a vector of integers, but this is proving much more difficult. I tried to convert the given examples to my use case (see below), but I just get an unhelpful segfault on the copy call. Frustratingly, everything I find is assuming string input/output to encode/decode. Any help is appreciated.
typedef
bi::transform_width<
bi::binary_from_base64<bi::remove_whitespace<string::const_iterator>>,
32, 6
>
base64_dec;
vector<int32_t> decoded_ints;
copy(
base64_dec(base64ints.cbegin()),
base64_dec(base64ints.cend()),
decoded_ints.begin()
);