非对称加密到底怎么样生成不同的密钥?找一天没找到边 - C++ Builder / Windows SDK/API
非对称加密到底怎么样生成不同的密钥?找一天没找到边
[解决办法]
CryptoAPI??没怎么用过。
http://www.wangchao.net.cn/bbsdetail_66820.html
//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);