Created
June 8, 2022 09:18
-
-
Save lingxd/8e8982b15b57cbd4092d3c6ba223aa22 to your computer and use it in GitHub Desktop.
C++ to base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/archive/iterators/binary_from_base64.hpp> | |
#include <boost/archive/iterators/base64_from_binary.hpp> | |
#include <boost/archive/iterators/transform_width.hpp> | |
#include <utility> | |
#include <memory> | |
#include <string> | |
#include <vector> | |
std::string to_base64(const std::vector<uint8_t>& buffer) { | |
using namespace boost::archive::iterators; | |
using It = base64_from_binary<transform_width<std::vector<unsigned char>::const_iterator, 6, 8>>; | |
auto base64 = std::string(It(buffer.begin()), It(buffer.end())); | |
return base64.append((3 - buffer.size() % 3) % 3, '='); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment