-
-
[求助]CryptAcquireContext调用总是不成功
-
发表于: 2007-7-19 19:39 5267
-
源代码如下:
// GetTickCount.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <wincrypt.h>
int _tmain(int argc, _TCHAR* argv[])
{
HCRYPTPROV hProv = 0;
if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) //这个hProv总是0,说明这个函数调用不成功
{
std::cout<< "wrong context!"<< std::endl;
return -1;
}
BYTE *pbBuffer = new byte(500);
if (!CryptGenRandom(hProv, 100, pbBuffer))
{
std::cout<< "wrong random!" << std::endl;
return -1;
}
if(!CryptReleaseContext(hProv, 0))
{
printf("Error %x during CryptReleaseContext!\n", GetLastError());
return -1;
}
return 0;
}
在WinXP sp2 + Visual Studio 2003 下编译通过。
但为什么CryptAcquireContext调用总是不成功,是不是缺了什么?
// GetTickCount.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <wincrypt.h>
int _tmain(int argc, _TCHAR* argv[])
{
HCRYPTPROV hProv = 0;
if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) //这个hProv总是0,说明这个函数调用不成功
{
std::cout<< "wrong context!"<< std::endl;
return -1;
}
BYTE *pbBuffer = new byte(500);
if (!CryptGenRandom(hProv, 100, pbBuffer))
{
std::cout<< "wrong random!" << std::endl;
return -1;
}
if(!CryptReleaseContext(hProv, 0))
{
printf("Error %x during CryptReleaseContext!\n", GetLastError());
return -1;
}
return 0;
}
在WinXP sp2 + Visual Studio 2003 下编译通过。
但为什么CryptAcquireContext调用总是不成功,是不是缺了什么?
赞赏
他的文章
- [分享]一个开源的keygenme 10467
- [原创]uCF2000 keygenme 1.0分析 8410
- [原创]bundy's keygenme #1分析 6835
赞赏
雪币:
留言: