当前位置: 技术问答>java相关
base64编码转换问题(在线。。。。。。。。。急)
来源: 互联网 发布时间:2015-10-22
本文导语: 请问有什么函数可以将base64转换成gb2312? | #include #include #include "Base64.h" //Base64Table contains the 64 printable characters static const char Base64Table[64]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012...
请问有什么函数可以将base64转换成gb2312?
|
#include
#include
#include "Base64.h"
//Base64Table contains the 64 printable characters
static const char Base64Table[64]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//Base64Encod
//Encode string
//Param: buftoenc,input string to encode
// bufsize,input string length
// encbug, output string encoded
//Return value:Encoded string length??? if fail return -1???
int Base64Encod(char *buftoenc,int bufsize,char *encbuf)
{
int i=0;
int b64byte[5];
unsigned char *buftemp;
//Allocate space for the temporary string
buftemp=(unsigned char *)malloc(bufsize+2);
strcpy(buftemp,buftoenc);
if (bufsize%3==1)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
}
if (bufsize%3==2)buftemp[bufsize]='';
while (i>2;
b64byte[1]=((buftemp[i]&3)4);
b64byte[2]=((buftemp[i+1]&0x0F)6);
b64byte[3]=buftemp[i+2]&0x3F;
encbuf[i+(i/3)]=Base64Table[b64byte[0]];
encbuf[i+(i/3)+1]=Base64Table[b64byte[1]];
encbuf[i+(i/3)+2]=Base64Table[b64byte[2]];
encbuf[i+(i/3)+3]=Base64Table[b64byte[3]];
i+=3;
}
free(buftemp);
if (bufsize%3==0)return bufsize*8/6;
if (bufsize%3==1)return((bufsize+2)*8/6)-2;
if (bufsize%3==2)return((bufsize+1)*8/6)-1;
return -1;
}
//Base64Decod
//Encode string
//Param: buftodec,input string to decode
// bufsize,input string length
// decbug, output string decoded
//Return value:Decoded string length??? if fail return -1???
int Base64Decod(char *buftodec,int bufsize,char *decbuf)
{
int i=0;
unsigned char binbyte[4];
int cpos[5];
unsigned char *buftemp;
//Allocate space for the temporary string
buftemp=(unsigned char *)malloc(bufsize);
strcpy(buftemp,buftodec);
if (bufsize%4==1)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
buftemp[bufsize+2]='';
}
if (bufsize%4==2)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
}
if (bufsize%4==3)buftemp[bufsize]='';
while (i
#include
#include "Base64.h"
//Base64Table contains the 64 printable characters
static const char Base64Table[64]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//Base64Encod
//Encode string
//Param: buftoenc,input string to encode
// bufsize,input string length
// encbug, output string encoded
//Return value:Encoded string length??? if fail return -1???
int Base64Encod(char *buftoenc,int bufsize,char *encbuf)
{
int i=0;
int b64byte[5];
unsigned char *buftemp;
//Allocate space for the temporary string
buftemp=(unsigned char *)malloc(bufsize+2);
strcpy(buftemp,buftoenc);
if (bufsize%3==1)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
}
if (bufsize%3==2)buftemp[bufsize]='';
while (i>2;
b64byte[1]=((buftemp[i]&3)4);
b64byte[2]=((buftemp[i+1]&0x0F)6);
b64byte[3]=buftemp[i+2]&0x3F;
encbuf[i+(i/3)]=Base64Table[b64byte[0]];
encbuf[i+(i/3)+1]=Base64Table[b64byte[1]];
encbuf[i+(i/3)+2]=Base64Table[b64byte[2]];
encbuf[i+(i/3)+3]=Base64Table[b64byte[3]];
i+=3;
}
free(buftemp);
if (bufsize%3==0)return bufsize*8/6;
if (bufsize%3==1)return((bufsize+2)*8/6)-2;
if (bufsize%3==2)return((bufsize+1)*8/6)-1;
return -1;
}
//Base64Decod
//Encode string
//Param: buftodec,input string to decode
// bufsize,input string length
// decbug, output string decoded
//Return value:Decoded string length??? if fail return -1???
int Base64Decod(char *buftodec,int bufsize,char *decbuf)
{
int i=0;
unsigned char binbyte[4];
int cpos[5];
unsigned char *buftemp;
//Allocate space for the temporary string
buftemp=(unsigned char *)malloc(bufsize);
strcpy(buftemp,buftodec);
if (bufsize%4==1)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
buftemp[bufsize+2]='';
}
if (bufsize%4==2)
{
buftemp[bufsize]='';
buftemp[bufsize+1]='';
}
if (bufsize%4==3)buftemp[bufsize]='';
while (i