May be for someone it will be useful function to converting CString to CString with Base64
const char _caMMI[64] = <br />
{ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',<br />
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',<br />
'0','1','2','3','4','5','6','7','8','9','+','/'};<br />
<br />
CString sGetBase64(CString a_sString )<br />
{<br />
CString l_sReturned;<br />
int l_iBlocks = a_sString.GetLength() / 3;<br />
long l_iValue = 0;<br />
for( int l_iBlock = 0 ; l_iBlock < l_iBlocks ; l_iBlock++ )<br />
{<br />
CString l_sTemp = "";<br />
l_iValue = 0;<br />
l_iValue = (char)(a_sString[l_iBlock*3]);<br />
l_iValue<<=8;<br />
l_iValue |= (char)(a_sString[l_iBlock*3+1]);<br />
l_iValue<<=8;<br />
l_iValue |= (char)(a_sString[l_iBlock*3+2]);<br />
<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp.MakeReverse();<br />
l_sReturned += l_sTemp;<br />
}<br />
if( a_sString.GetLength() - l_iBlocks*3 == 2 )<br />
{<br />
CString l_sTemp = "";<br />
l_iValue = 0;<br />
l_iValue = (char)(a_sString[l_iBlocks*3]);<br />
l_iValue<<=8;<br />
l_iValue |= (char)(a_sString[l_iBlocks*3+1]);<br />
l_iValue<<=8;<br />
<br />
<br />
l_sTemp+= '=';<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp.MakeReverse();<br />
l_sReturned+=l_sTemp;<br />
}<br />
if( a_sString.GetLength() - l_iBlocks*3 == 1 )<br />
{<br />
CString l_sTemp = "";<br />
l_iValue = 0;<br />
l_iValue = (char)(a_sString[l_iBlocks*3]);<br />
l_iValue<<=8;<br />
l_iValue |= (char)(a_sString[l_iBlocks*3+1]);<br />
l_iValue<<=8;<br />
<br />
l_sTemp+= '=';<br />
l_iValue>>=6;<br />
l_sTemp+= '=';<br />
l_iValue>>=6;<br />
l_sTemp+= _caMMI[l_iValue & 0x3F];<br />
l_iValue>>=6;<br />
l_sTemp.MakeReverse();<br />
l_sReturned+=l_sTemp;<br />
}<br />
<br />
return l_sReturned;<br />
}<br />
|