Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8066821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:06:51+00:00 2026-06-05T12:06:51+00:00

I trying to use boost base64 encoder, I found an example but I got

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:06:52+00:00Added an answer on June 5, 2026 at 12:06 pm

    Unfortunately the combination of the two iterator_adaptors binary_from_base64 and transform_width is 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:

    #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/insert_linebreaks.hpp>
    #include <boost/archive/iterators/remove_whitespace.hpp>
    #include <iostream>
    #include <string>
    
    using namespace boost::archive::iterators;
    using namespace std;
    
    int main(int argc, char **argv) {
      typedef transform_width< binary_from_base64<remove_whitespace<string::const_iterator> >, 8, 6 > it_binary_t;
      typedef insert_linebreaks<base64_from_binary<transform_width<string::const_iterator,6,8> >, 72 > it_base64_t;
      string s;
      getline(cin, s, '\n');
      cout << "Your string is: '"<<s<<"'"<<endl;
    
      // Encode
      unsigned int writePaddChars = (3-s.length()%3)%3;
      string base64(it_base64_t(s.begin()),it_base64_t(s.end()));
      base64.append(writePaddChars,'=');
    
      cout << "Base64 representation: " << base64 << endl;
    
      // Decode
      unsigned int paddChars = count(base64.begin(), base64.end(), '=');
      std::replace(base64.begin(),base64.end(),'=','A'); // replace '=' by base64 encoding of '\0'
      string result(it_binary_t(base64.begin()), it_binary_t(base64.end())); // decode
      result.erase(result.end()-paddChars,result.end());  // erase padding '\0' characters
      cout << "Decoded: " << result << endl;
      return 0;
    }
    

    Note that I added the insert_linebreaks and remove_whitespace iterators, 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:

    $ ./base64example
    Hello World!
    Your string is: 'Hello World!'
    Base64 representation: SGVsbG8gV29ybGQh
    Decoded: Hello World!
    $ ./base64example
    Hello World!!
    Your string is: 'Hello World!!'
    Base64 representation: SGVsbG8gV29ybGQhIQ==
    Decoded: Hello World!!
    $ ./base64example
    Hello World!!!
    Your string is: 'Hello World!!!'
    Base64 representation: SGVsbG8gV29ybGQhISE=
    Decoded: Hello World!!!
    

    You can check the base64 strings with this online-encoder/decoder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use BOOST_FOREACH for iterating through the std::queue. But there isn't iterators
I'm trying to use the Gamma distribution from boost::math but it looks like it
I'm trying to use Boost's multi-index container for fast look up, but I'm having
I'm trying to use the boost library in my code but get the following
I am trying to use boost string algorithms for case insensitive search. total newbie
I am trying to use Boost's lexical_cast for my C++ project but am running
I'm trying to use the boost threads, but when running the program i get
I'm trying to use Boost::bind and std::copy to print out the values in a
I'm trying to use boost unit testing alongside the Allegro graphics library, but both
I'm trying to use boost::exception and have condensed my prototype code down to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.