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);
}
}
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);
}
}
解决方案 »
- 学习mfc的求助
- C++通过ADO调用存储过程时如果作为用于返回的参数所含的字符太多就会出错。
- SDI的菜单怎么修改啊?
- Dll : 为什么VC开发的Dll函数参数 char* 在VB中不能调用(再问)?
- ████████████████████████████████████████████████████████████████
- 请大家都来帮我!!高分相赠。来者有分!!!快来啊!!!急!!!!!
- score for Cline(营营)
- 求平衡树算法,给出注释。
- csdn号称中国最大的技术论坛,为什么这个问题无人直答?
- 如何获得网页页面Form中的内容?救急
- vc编辑框日文显示乱码
- VC++中自绘的CListBox控件如何删除一个Item
这篇文章将给你截获,请注意看最后一段说明。
#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
Declared in Wincrypt.h.
Library
Use Crypt32.lib.
DLL
Requires Crypt32.dll.
按照1楼的做
{
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
);
这两段是你自己写的?
最后在VC工程中的stdafx.h中加入宏定义#define _WIN32_WINNT 0x500。加了吗?