描述:
BOOL CTVMSKEncrypt::Decrypt(CString strToDecrypt,CString strDecryptParam,CString &strDecryptResult)
{
strDecryptResult.Empty();
int nLen =strToDecrypt.GetLength();
int nPLen =strDecryptParam.GetLength();
if(strToDecrypt.GetLength() != 100)
{
return FALSE;
}
int nRealPassLen = strToDecrypt.GetAt(60) - 65;
int nRealParaLen = strToDecrypt.GetAt(61) - 65;
if(nRealParaLen != nPLen)
{
return FALSE;
}
for(int i=0; i<nPLen;i++)
{
if(strToDecrypt[i+62]-1 != strDecryptParam[i])
{
return FALSE;
}
if(::IsDBCSLeadByte(strDecryptParam[i]))
{
i++;
if(strToDecrypt[i+62] != strDecryptParam[i])
{
return FALSE;
}
}
}
for(i=0;i<nRealPassLen;i++)
{
char ch = strToDecrypt.GetAt(i);
char ch1 = strDecryptParam.GetAt(i%nPLen);
int nBit = i%8;
int nMask = 1 << nBit;
int nRes = ch1&nMask;
if(nRes > 0)
{
ch -= 2;
}
else
{
ch -= 1;
}
strDecryptResult.Insert(i,ch);
if(::IsDBCSLeadByte(ch))
{
i++;
strDecryptResult.Insert(i,strToDecrypt.GetAt(i));
}
}
return TRUE;
}
解决方案1:
_com_util::ConvertStringToBSTR()
解决方案2:#include<altstr.h>就可以在ATL里用CString了