ただし、末尾の長さ調整のための"="は付加してくれませんので、自分で付加する必要があります。
#include <string>
#include <sstream>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
using namespace boost::archive::iterators;
// 折り返し列幅
#define BASE64_COLUMN_WIDTH 76
typedef
insert_linebreaks<
base64_from_binary<
transform_width<
const char *,
6,
8
>
>
,BASE64_COLUMN_WIDTH
>
base64_encoder;
std::string decode_base64(const std::string& src_data)
{
// エンコードしたデータを格納
std::stringstream ost_base64;
// エンコード処理
std::copy(
base64_encoder(src_data.c_str()),
base64_encoder(src_data.c_str() + src_data.length()),
std::ostream_iterator<char>(ost_base64)
);
std::string base64 = ost_base64.str();
// 末尾の長さ調整
while( ((base64.length() % (BASE64_COLUMN_WIDTH + 1)) % 4) > 0 ){
base64 += "=";
}
return base64;
}
