32 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
33 "abcdefghijklmnopqrstuvwxyz"
38 return (isalnum(c) || (c ==
'+') || (c ==
'/'));
41 std::string
base64_encode(
unsigned char const* bytes_to_encode,
unsigned int in_len) {
45 unsigned char char_array_3[3];
46 unsigned char char_array_4[4];
49 char_array_3[i++] = *(bytes_to_encode++);
51 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
52 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
53 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
54 char_array_4[3] = char_array_3[2] & 0x3f;
56 for(i = 0; (i <4) ; i++)
64 for(j = i; j < 3; j++)
65 char_array_3[j] =
'\0';
67 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
68 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
69 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
70 char_array_4[3] = char_array_3[2] & 0x3f;
72 for (j = 0; (j < i + 1); j++)
85 int in_len = encoded_string.size();
89 unsigned char char_array_4[4], char_array_3[3];
92 while (in_len-- && ( encoded_string[in_] !=
'=') &&
is_base64(encoded_string[in_])) {
93 char_array_4[i++] = encoded_string[in_]; in_++;
95 for (i = 0; i <4; i++)
98 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
99 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
100 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
102 for (i = 0; (i < 3); i++)
103 ret += char_array_3[i];
109 for (j = i; j <4; j++)
112 for (j = 0; j <4; j++)
115 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
116 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
117 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
119 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
#define base64_decode(in, inlen, out, outlen)
static const std::string base64_chars
std::string base64_encode(unsigned char const *, unsigned int len)
static bool is_base64(unsigned char c)