首页
社区
课程
招聘
[求助]CryptAcquireContext调用总是不成功
发表于: 2007-7-19 19:39 5267

[求助]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调用总是不成功,是不是缺了什么?

[培训]科锐逆向工程师培训第53期2025年7月8日开班!

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回