使用了这个API生成了RDP(远程桌面)文件里面的密码,如果用CryptUnprotectData来还原是能的到明文的。
但是把这密码写到RDP文件里面,却不能进行远程桌面连接,就是报象密码错误那样的错误。

解决方案 »

  1.   

    啥意思,不太明白。
    我生成密码的代码如下:
    MakeUdpPsw(char * dest,char * sour)  //必须确保dest的空间足够(一般大于500)
    {
    DATA_BLOB DataIn;
        DATA_BLOB DataOut;
    BYTE *pbDataInput =(BYTE *)sour;
        DWORD cbDataInput =strlen(sour)*sizeof(char);

        DataIn.pbData = pbDataInput;
        DataIn.cbData = cbDataInput;

        

        if(CryptProtectData(
            &DataIn,
            L"psw",                                // A description string
    // to be included with the
    // encrypted data.
            NULL,                               // Optional entropy not used.
            NULL,                               // Reserved.
            NULL,                               // Pass NULL for the
    // prompt structure.
            0,
            &DataOut))
        {
            printf("The encryption phase worked.\n");

            

            int count=0;

            while ( count <= (int)DataOut.cbData )
    {
                // 因为一个unsigned int 占32位
                // 转换成成16进制要占两位
                // 所以这里需要用%02
    char t[3] = {0};            
    sprintf(t,"%02X",DataOut.pbData[count]);

    printf("%02X",DataOut.pbData[count]);
    strcat(dest,t);
                count++;
            }
    return TRUE;
    }
    else
    {
    return FALSE;
    }

    }
      

  2.   

     while ( count <= (int)DataOut.cbData )这个应该是有问题,把<=改为<,也一样。
      

  3.   

    结贴 ,是字符编码(多字节、UNICODE)的问题。