I have de following code:
class CBase64
{
public:
int encode(unsigned char* aPlain,char** aOut,int aInlen);
int decode(char* aPlain, std::string& strout);
};
int CBase64::encode(unsigned char* aPlain,char** aOut,int aInlen)
{
int i;
BIO *mbio,*b64bio,*bio;
char* p=(char*)NULL;
mbio=BIO_new(BIO_s_mem());
b64bio=BIO_new(BIO_f_base64());
//BIO_set_flags(b64bio,BIO_FLAGS_BASE64_NO_NL);
bio=BIO_push(b64bio,mbio);
BIO_write(bio,aPlain,aInlen);
BIO_flush(bio);
i=(int)BIO_ctrl(mbio,BIO_CTRL_INFO,0,(char *)&p);
if(i>0) {
*aOut=(char*)malloc(i);
memcpy(*aOut,p,i);
}
BIO_free_all(bio);
return i;
}
int CBase64::decode(char* aPlain, std::string& strout)
{
int i;
BIO *mbio,*b64bio,*bio;
unsigned char *buf;
mbio=BIO_new(BIO_s_mem());
b64bio=BIO_new(BIO_f_base64());
//BIO_set_flags(b64bio,BIO_FLAGS_BASE64_NO_NL);
BIO_puts(mbio,aPlain);
BIO_flush(mbio);
bio=BIO_push(b64bio,mbio);
size_t t= BIO_ctrl_pending(bio);
buf = (unsigned char*)malloc(t);
i=BIO_read(bio, (void*)buf, t);
if(i>0)
{
strout.append((char*)buf,i);
}
BIO_free_all(bio);
return i;
}
int main(int argc, char* argv[])
{
// this is just a sample
int n=1000;
std::string str(n,'w');
CBase64 b;
char* out=0;
b.encode((unsigned char*)str.c_str(),&out,str.length());
std::string strout;
b.decode(out,strout);
return 0;
}
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]