I trying to use boost base64 encoder, I found an example but I got and exception
typedef
transform_width< binary_from_base64<std::string::const_iterator>, 8, 6 > it_binary_t
an I used
std::string b64E(it_binary_t(Encrip.begin()), it_binary_t(Encrip.end()));
I get it
Unhandled exception at 0x75b1b9bc in agentid_coder.exe: Microsoft C++
exception: boost::archive::iterators::dataflow_exception at memory
location 0x0046ed94..
I found this workaround but I get the same result
string dec(
it_binary_t(Encrip.begin()),
it_binary_t(Encrip.begin() + Encrip.length() - 1)
);
I am using MSVS2008 and boost 1.38
Unfortunately the combination of the two
iterator_adaptorsbinary_from_base64andtransform_widthis not a complete base64 encoder/decoder. Base64 represents groups of 24 bits (3 bytes) as 4 characters, each of which encodes 6 bits. If the input data is not an integer multiple of such 3 byte groups it has to be padded with one or two zero bytes. To indicate how many padding bytes were added, one or two=characters are appended to the encoded string.transform_width, which is responsible for the 8bit binary to 6bit integer conversion does not apply this padding automatically, it has do be done by the user. A simple example:Note that I added the
insert_linebreaksandremove_whitespaceiterators, so that the base64 output is nicely formatted and base64 input with line breaks can be decoded. These are optional though.Run with different input strings which require different padding:
You can check the base64 strings with this online-encoder/decoder.