首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

非对称加密到底如何样生成不同的密钥?找一天没找到边

2012-02-29 
非对称加密到底怎么样生成不同的密钥?找一天没找到边 - C++ Builder / Windows SDK/API非对称加密到底怎么

非对称加密到底怎么样生成不同的密钥?找一天没找到边 - C++ Builder / Windows SDK/API
非对称加密到底怎么样生成不同的密钥?找一天没找到边

[解决办法]
CryptoAPI??没怎么用过。

http://www.wangchao.net.cn/bbsdetail_66820.html

C/C++ code
//Example#include <wincrypt.h>  HCRYPTPROV hProv = 0;HCRYPTKEY hKey = 0;DWORD dwMode;BYTE pbData[16];DWORD dwCount;DWORD i;// Get handle to user default provider.if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) {    printf("Error %x during CryptAcquireContext!\n", GetLastError());    goto done;}// Create random block cipher session key.if(!CryptGenKey(hProv, CALG_RC2, CRYPT_EXPORTABLE, &hKey)) {    printf("Error %x during CryptGenKey!\n", GetLastError());    goto done;}// Read the cipher mode.dwCount = sizeof(DWORD);if(!CryptGetKeyParam(hKey, KP_MODE, &dwMode, &dwCount, 0)) {    printf("Error %x during CryptGetKeyParam!\n", GetLastError());    goto done;}assert(dwCount==sizeof(BYTE));// Print out cipher mode.printf("Default cipher mode:%d\n", dwMode);// Read initialization vector.dwCount = 16;if(!CryptGetKeyParam(hKey, KP_IV, pbData, &dwCount, 0)) {    printf("Error %x during CryptGetKeyParam!\n", GetLastError());    goto done;}// Print out initialization vector.printf("Default IV:");for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]);printf("\n");done:// Destroy session key.if(hKey != 0) CryptDestroyKey(hKey);// Release provider handle.if(hProv != 0) CryptReleaseContext(hProv, 0); 

热点排行