Hello.
Someone know if exist any API or any way to encode a ANSI string to Base64?
Thanks
Printable View
Hello.
Someone know if exist any API or any way to encode a ANSI string to Base64?
Thanks
Should be free libraries floating around out there. GIYF.
Code:CString Base64Encode(LPCTSTR src)
{
if( !src )
return( _T("") );
int size = static_cast<int> (strlen( src ));
CString out;
LPSTR p = out.GetBuffer( size*4/3+5);
for(int i=0; i<size; i+=3)
{
unsigned char b1=0, b2=0, b3=0, b4=0, b5=0, b6=0, b7=0;
b1 = src[i];
if(i+1<size)
b2 = src[i+1];
if(i+2<size)
b3 = src[i+2];
b4= b1>>2;
b5= ((b1&0x3)<<4)|(b2>>4);
b6= ((b2&0xf)<<2)|(b3>>6);
b7= b3&0x3f;
*p++= encode(b4);
*p++= encode(b5);
if(i+1<size) {
*p++= encode(b6);
} else {
*p++= '=';
}
if(i+2<size) {
*p++= encode(b7);
} else {
*p++= '=';
}
}
*p = '\0';
out.ReleaseBuffer();
return( out );
}
// Base64 encode one byte
char CBasicAuth::encode(unsigned char u)
{
if(u < 26) return 'A' + u;
if(u < 52) return 'a' + (u - 26);
if(u < 62) return '0' + (u - 52);
if(u == 62) return '+';
return '/';
}
This isn't a search engine, don't encourage it.
Not to mention it's C++ in the C section.
Not to also mention it appears to be MFC/Windows-specific C++.
I wrote one some time ago.
http://www.acc.umu.se/~onionkgt/stuff/base64.tar.gz