void _encodeBase64(unsigned char *in, unsigned char *out)
{
static const unsigned char encodeBase64Map[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
out[0] = encodeBase64Map[(in[0] >> 2) & 0x3F];
out[1] = encodeBase64Map[((in[0] << 4) & 0x30) | ((in[1] >> 4) & 0x0F)];
out[2] = encodeBase64Map[((in[1] << 2) & 0x3C) | ((in[2] >> 6) & 0x03)];
out[3] = encodeBase64Map[in[2] & 0x3F];
}
int encodeBase64(unsigned char *inbuf, int insize, unsigned char *outbuf, int outsize)
{
int inpos = 0, outpos = 0;
while(inpos != insize) {
if(inpos + 3 <= insize) {
if(outpos + 4 > outsize)
return -1;
_encodeBase64(inbuf + inpos, outbuf + outpos);
inpos += 3;
outpos += 4;
}
if(insize - inp
Base64 Encode/Decode in C/C++
最新推荐文章于 2022-10-20 16:11:53 发布