14 #include <openssl/buffer.h> 15 #include <openssl/md5.h> 23 BIO *b64 = BIO_new(BIO_f_base64());
27 BIO *bmem = BIO_new(BIO_s_mem());
28 if (bmem ==
nullptr) {
36 BIO *chain = BIO_push(b64, bmem);
37 if (chain ==
nullptr) {
41 BIO_set_flags(chain, BIO_FLAGS_BASE64_NO_NL);
42 BIO_write(chain, text.
begin(), text.
size());
43 if (BIO_flush(chain) != 1) {
48 BIO_get_mem_ptr(chain, &bptr);
50 if (bptr && bptr->length > 0) {
51 result =
std::string((
char *)bptr->data, bptr->length);
61 static_assert(MD5_DIGEST_LENGTH == 16,
"");
63 unsigned char digest[MD5_DIGEST_LENGTH];
67 std::ostringstream ss;
68 ss << std::hex << std::setfill(
'0');
69 for(
int i = 0;
i < MD5_DIGEST_LENGTH;
i++) {
70 ss << std::setw(2) << (
unsigned int)digest[
i];
constexpr size_type size() const
std::string base64Encode(folly::ByteRange text)
std::string md5Encode(folly::ByteRange text)
constexpr Iter begin() const