Hi I have the complete solution:
bool CrypttoBase64Encode(BYTE* pbSource, DWORD dwSourceLength, CString& sBase64)
{
bool bResult = false;
DWORD dwDestLength = 0;
LPTSTR psDest = NULL;
if (CryptBinaryToString(pbSource, dwSourceLength, CRYPT_STRING_BASE64, NULL, &dwDestLength) == TRUE)
{
psDest = new TCHAR[dwDestLength + 1];
if (CryptBinaryToString(pbSource, dwSourceLength, CRYPT_STRING_BASE64, psDest, &dwDestLength) == TRUE)
{
sBase64 = CString(psDest);
sBase64 = sBase64.Left(sBase64.GetLength() - 2);
bResult = true;
}
delete[] psDest;
}
return bResult;
}
int main()
{
CString s = _T("Hello, world!");
LPBYTE pByte = new BYTE[(s.GetLength()) * 2];
memcpy(pByte, s, (s.GetLength()) * 2);
CrypttoBase64Encode(pByte, (s.GetLength()) * 2, s);
delete[] pByte;
return 0;
}
With this you obtain a complete string encoding in UTF16 LE (unicode)