RDP文件里的密码算法,说是WINDOWS提供的API,怎么'CryptProtectData' : undeclared identifier?已经#include <Wincrypt.h>了/******************************************************************************/
include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
typedef   struct   _CRYPTOAPI_BLOB   { 
DWORD         cbData; 
BYTE*         pbData; 
}   DATA_BLOB,                       *PDATA_BLOB;
void main()
{    DATA_BLOB DataIn;
    DATA_BLOB DataOut;
    // mstsc.exe中使用的是unicode,所以必须做宽字符转换
    BYTE *pbDataInput =(BYTE *)L"freedom";
    DWORD cbDataInput = wcslen(L"freedom")*sizeof(wchar_t);    DataIn.pbData = pbDataInput;
    DataIn.cbData = cbDataInput;    FILE *fp;    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
            printf(fp,"%02X",DataOut.pbData[count]);
            count++;
        }

        

    }
    else
    {
        printf("Encryption error using CryptProtectData.\n");
        exit(1);
    }
}

解决方案 »

  1.   

    #pragma comment(lib, "Crypt32.lib")
      

  2.   

    看看CryptProtectData是在哪声明的,估计还需要include别的头文件
      

  3.   

    http://www.chinaitpower.com/A/2001-10-14/1700.html
    这篇文章将给你截获,请注意看最后一段说明。
      

  4.   

    MS现在已经不提供PlatformSDK下载了,于是我把VS2008里面的crypt32.lib和WinCrypt.h都拷到该工程里面去(VC6),编译还是提示找不到函数,于是我从WinCrypt.h里把该函数和他用到的一个结构都复制过来声明在CPP里,现在报module machine type "ARM" conflicts with target machine type "IX86"....
      

  5.   

    完全按照3楼的做了,装了PSDK,然后把里面的那两文件拷贝到当前工程内,然后:
    #include "stdafx.h"#include <stdio.h>
    #include <windows.h>
    #include "e:\\myprojects\\consoletest\\WinCrypt.h"
    #pragma comment(lib,"e:\\myprojects\\consoletest\\Crypt32.lib")typedef struct  _CRYPTPROTECT_PROMPTSTRUCT
    {
        DWORD cbSize;
        DWORD dwPromptFlags;
        HWND  hwndApp;
        LPCWSTR szPrompt;
    } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;WINCRYPT32API
    BOOL
    WINAPI
    CryptProtectData(
     IN              DATA_BLOB*      pDataIn,
     IN              LPCWSTR         szDataDescr,
     IN OPTIONAL     DATA_BLOB*      pOptionalEntropy,
     IN              PVOID           pvReserved,
     IN OPTIONAL     CRYPTPROTECT_PROMPTSTRUCT*  pPromptStruct,
     IN              DWORD           dwFlags,
     OUT             DATA_BLOB*      pDataOut            // out encr blob
        );
    还是:
    rror LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall CryptProtectData(struct _CRYPTOAPI_BLOB *,unsigned short const *,struct _CRYPTOAPI_BLOB *,void *,struct _CRYPTPROTECT_PROMPTSTRUCT *,unsigned long,struc
    t _CRYPTOAPI_BLOB *)" (__imp_?CryptProtectData@@YGHPAU_CRYPTOAPI_BLOB@@PBG0PAXPAU_CRYPTPROTECT_PROMPTSTRUCT@@K0@Z)
    Debug/consoleTest.exe : fatal error LNK1120: 1 unresolved externals
      

  6.   

    Header
     Declared in Wincrypt.h.
     
    Library
     Use Crypt32.lib.
     
    DLL
     Requires Crypt32.dll.
     
    按照1楼的做
      

  7.   

    typedef struct _CRYPTPROTECT_PROMPTSTRUCT
    {
      DWORD cbSize;
      DWORD dwPromptFlags;
      HWND hwndApp;
      LPCWSTR szPrompt;
    } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;WINCRYPT32API
    BOOL
    WINAPI
    CryptProtectData(
    IN DATA_BLOB* pDataIn,
    IN LPCWSTR szDataDescr,
    IN OPTIONAL DATA_BLOB* pOptionalEntropy,
    IN PVOID pvReserved,
    IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
    IN DWORD dwFlags,
    OUT DATA_BLOB* pDataOut // out encr blob
      );
    这两段是你自己写的?
      

  8.   

    从WinCrypt.h里复制出来的,因为不知道为什么就算INCLUDE这个都文件了,也说这两东西未声明,于是我直接复制过来。
      

  9.   

    That's diffcult to me! so i want you can "解决" this prombel.go ahead!
      

  10.   

    在WinCrypt.h中能找到这两个数据结构吗?
    最后在VC工程中的stdafx.h中加入宏定义#define _WIN32_WINNT 0x500。加了吗?
      

  11.   

    另装了一套PSDK,然后在VC6的INCLUDE和LIB里面增加了新装的东西,并放到第一位,然后#pragma comment(lib, "Crypt32.lib")。解决了。