34 static const std::string m_base64_chars =
35 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
36 "abcdefghijklmnopqrstuvwxyz"
38 return m_base64_chars;
41 static inline bool is_base64(
unsigned char c) {
42 return (isalnum(c) || (c ==
'+') || (c ==
'/'));
45 std::string
base64_encode(
unsigned char const* bytes_to_encode,
unsigned int in_len);
48 char const* s = enc.c_str();
51 std::string
base64_encode(
unsigned char const* bytes_to_encode,
unsigned int in_len) {
56 unsigned char char_array_3[3];
57 unsigned char char_array_4[4];
60 char_array_3[i++] = *(bytes_to_encode++);
62 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
63 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
64 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
65 char_array_4[3] = char_array_3[2] & 0x3f;
67 for(i = 0; (i <4) ; i++)
75 for(j = i; j < 3; j++)
76 char_array_3[j] =
'\0';
78 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
79 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
80 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
81 char_array_4[3] = char_array_3[2] & 0x3f;
83 for (j = 0; (j < i + 1); j++)
97 int in_len = encoded_string.size();
101 unsigned char char_array_4[4], char_array_3[3];
104 while (in_len-- && ( encoded_string[in_] !=
'=') && is_base64(encoded_string[in_])) {
105 char_array_4[i++] = encoded_string[in_]; in_++;
107 for (i = 0; i <4; i++)
110 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
111 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
112 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
114 for (i = 0; (i < 3); i++)
115 ret += char_array_3[i];
121 for (j = i; j <4; j++)
124 for (j = 0; j <4; j++)
127 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
128 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
129 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
131 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];