bool MBCSToWide(char * MBCS,WCHAR * Wide)
{
if (!MBCS || !Wide)
{
return false;
}
MultiByteToWideChar(CP_OEMCP,MB_PRECOMPOSED,MBCS,strlen(MBCS),Wide,254);
return true;
}
bool EncryptPassword(char * Password,char * Buffer,int * BufferLen)
{
if(!Password || !Buffer || !BufferLen || *BufferLen <= 0){
return false;
}
WCHAR WPass[255];
MBCSToWide(Password,WPass);
int Len = strlen(Password) * sizeof(WCHAR);
DATA_BLOB Input;
DATA_BLOB Output;
Input.pbData = (BYTE *)WPass;
Input.cbData = Len;
if(CryptProtectData(&Input,L"Password",NULL,NULL,NULL,0,&Output)){
for(int i = 0;i < Output.cbData;i++){
sprintf(Buffer + i * 2,"%02X",Output.pbData[i]);
}
*BufferLen =