#include "crypto/encode/base64.h" static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; static inline bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); } std::string Base64::Encode(const std::string& src) { std::string ret; unsigned char char_array_3[3]; unsigned char char_array_4[4]; size_t srcLen = src.length(); const char* pSrc = src.c_str(); size_t i = 0; while (srcLen--) { char_array_3[i++] = *(pSrc++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (i = 0; (i <4); i++) ret += base64_chars[char_array_4[i]]; i = 0; } } size_t j = 0; if (i) { for (j = i; j < 3; j++) char_array_3[j] = '