unsigned char * base64= (unsigned char *) "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="; CString Base64Encode (CString src,int srclen) {int n,buflen,i,j; static unsigned char *dst; CString buf=src; Buflen=n=srclen; dst= (unsigned char*) malloc (buflen/3*4+3); memset (dst,0,buflen/3*4+3); for (i=0,j=0;i<=buflen-3;i+=3,j+=4) {dst[j]= (BUF[I]&0XFC) >>2; dst[j+1]= ((buf[i]&0x03) <<4) + ((buf[i+1]&0xf0) >>4); Dst[j+2]= ((buf[i+1]&0x0f) <<2) + ((buf[i+2]&0xc0) >>6); dst[j+3]=buf[i+2]&0x3f; if (n%3==1) {dst[j]= (BUF[I]&0XFC) >>2; dst[j+1]= ((buf[i]&0x03) <<4); dst[j+2]=64; dst[j+3]=64 = 4; else if (n%3==2) {dst[j]= (BUF[I]&0XFC) >>2; dst[j+1]= ((buf[i]&0x03) <<4) + ((buf[i+1]&0xf0) >>4); Dst[j+2]= ((buf[i+1]&0x0f) <<2); dst[j+3]=64; j+=4; for (i=0;i<j;i++)/* Map 6 bit value to Base64 ASCII character/dst[i]=base64[(int) dst[i]]; dst[j]=0; Return CString (DST); } CString BAse64decode (CString inpt,int * len) {int n,i,j,pad; unsigned char *p; static unsigned char *dst; unsigned char * SRC; *le n=0; Pad=0; N=INPT. GetLength (); src=new unsigned char [n]; for (i=0;i<n;i++) src[i]=inpt[i]; while (n>0&&src[n-1]== ' = ') {src[n-1]=0; pad++ n--;} for (i=0;i<n;i++) {/* map base64 ASCII character to 6 Bit value */p= (unsigned char *) STRCHR (const char *) base64, (int) src[i]); if (!p) break; src[i]=p-(unsigned char *) base64; } dst= (unsigned char *) malloc (n*3/4+1); memset (dst,0,n*3/4+1); for (i=0,j=0;i<n;i+=4,j+=3) {dst[j]= (src[i]<<2) + ((src[i+1]&0x30) >>4); dst[j+1]= ((src[i+1]& 0x0f) (<<4) + ((src[i+2]&0x3c) >>2); Dst[j+2]= ((src[i+2]&0x03) <<6) + src[i+3]; *len+=3; } *len-=pad; Return CString (DST); }