这篇教程C++ CryptAcquireContext函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CryptAcquireContext函数的典型用法代码示例。如果您正苦于以下问题:C++ CryptAcquireContext函数的具体用法?C++ CryptAcquireContext怎么用?C++ CryptAcquireContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CryptAcquireContext函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: entropy_funint entropy_fun(unsigned char buf[], unsigned int len){ HCRYPTPROV provider; unsigned __int64 pentium_tsc[1]; unsigned int i; int result = 0; if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { result = CryptGenRandom(provider, len, buf); CryptReleaseContext(provider, 0); if (result) return len; } QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc); for(i = 0; i < 8 && i < len; ++i) buf[i] = ((unsigned char*)pentium_tsc)[i]; return i;}
开发者ID:manuelkasper,项目名称:objective-zip,代码行数:23,
示例2: arc4_seed_win32static intarc4_seed_win32(void){ /* This is adapted from Tor's crypto_seed_rng() */ static int provider_set = 0; static HCRYPTPROV provider; unsigned char buf[ADD_ENTROPY]; if (!provider_set) { if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { if (GetLastError() != (DWORD)NTE_BAD_KEYSET) return -1; } provider_set = 1; } if (!CryptGenRandom(provider, sizeof(buf), buf)) return -1; arc4_addrandom(buf, sizeof(buf)); memset(buf, 0, sizeof(buf)); arc4_seeded_ok = 1; return 0;}
开发者ID:OpenSXCE-org,项目名称:FireFox-43-port-for-all-OpenSolaris-distros,代码行数:23,
示例3: getrandom_charsunsigned intgetrandom_chars(int desired, unsigned char *buf, int lenbuf) { HCRYPTPROV hcryptprov; BOOL err; if (buf == NULL || lenbuf <= 0 || desired > lenbuf) return (0); /* * The first time we just try to acquire the context */ err = CryptAcquireContext(&hcryptprov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); if (!err){ return (0); } if (!CryptGenRandom(hcryptprov, desired, buf)) { CryptReleaseContext(hcryptprov, 0); return (0); } CryptReleaseContext(hcryptprov, 0); return (desired);}
开发者ID:Hal-Murray,项目名称:ntp,代码行数:23,
示例4: CreateKeysetBOOL CreateKeyset(HCRYPTPROV *hProv) { HCRYPTKEY hXchgKey; LONG error; if(!CryptAcquireContext(hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) return FALSE; if(!CryptGenKey(*hProv,AT_SIGNATURE,0,&hXchgKey)) { error=GetLastError(); CryptReleaseContext(*hProv, 0); SetLastError(error); return FALSE; } CryptDestroyKey(hXchgKey); if(!CryptGenKey(*hProv,AT_KEYEXCHANGE,CRYPT_EXPORTABLE,&hXchgKey)) { error=GetLastError(); CryptReleaseContext(*hProv, 0); SetLastError(error); return FALSE; } CryptDestroyKey(hXchgKey); return TRUE;}
开发者ID:carsten-clauss,项目名称:MP-MPICH,代码行数:23,
示例5: exsltCryptoCryptoApiHash/** * exsltCryptoCryptoApiHash: * @ctxt: an XPath parser context * @algorithm: hashing algorithm to use * @msg: text to be hashed * @msglen: length of text to be hashed * @dest: buffer to place hash result * * Helper function which hashes a message using MD4, MD5, or SHA1. * Uses Win32 CryptoAPI. */static voidexsltCryptoCryptoApiHash (xmlXPathParserContextPtr ctxt, ALG_ID algorithm, const char *msg, unsigned long msglen, char dest[HASH_DIGEST_LENGTH]) { HCRYPTPROV hCryptProv; HCRYPTHASH hHash; if (!CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { exsltCryptoCryptoApiReportError (ctxt, __LINE__); return; } hHash = exsltCryptoCryptoApiCreateHash (ctxt, hCryptProv, algorithm, msg, msglen, dest, HASH_DIGEST_LENGTH); if (0 != hHash) { CryptDestroyHash (hHash); } CryptReleaseContext (hCryptProv, 0);}
开发者ID:ArielleBassanelli,项目名称:gempak,代码行数:34,
示例6: read_RSA_key/** * Loads an RSA private key from the specified key container */RSA_key_t read_RSA_key(const char *container){ int idx, found; const char *_container; // First find available private key slot for (idx = 0, found = 0; (idx < MAXLIST) && (!found); idx++) { if (private_key_list[idx].provider == 0) { found = 1; } } if (!found) { log(0, 0, "Couldn't find empty key slot for private key"); return (RSA_key_t)NULL; } idx--; if (!strcmp(container, "")) { _container = DEF_KEY_CONTAINER; } else { _container = container; } if (!CryptAcquireContext(&private_key_list[idx].provider, _container, NULL, prov_type, machine_keyset)) { mserror("CryptAcquireContext failed"); return (RSA_key_t)NULL; } if (!CryptGetUserKey(private_key_list[idx].provider, AT_KEYEXCHANGE, &private_key_list[idx].key)) { mserror("CryptGetUserKey failed"); return (RSA_key_t)NULL; } return (RSA_key_t)private_key_list[idx].key;}
开发者ID:b-cuts,项目名称:uftp,代码行数:40,
示例7: init_randomstatic void init_random(){ #ifdef WIN32 HCRYPTPROV wctx;#else FILE *fp = 0;#endif unsigned char buff[64]; if (g_initialized) return; #ifdef WIN32 CryptAcquireContext(&wctx, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); CryptGenRandom(wctx, sizeof(buff), (BYTE*) buff); CryptReleaseContext(wctx, 0); g_initialized = 1; #else fp = fopen("/dev/urandom", "r"); if (fp) { size_t read = fread(buff, sizeof(buff), 1, fp); g_initialized = read == 1; fclose(fp); }#endif if (g_initialized) RAND_seed( buff, sizeof(buff) );}
开发者ID:cocagne,项目名称:csrp,代码行数:37,
示例8: randombytesvoid randombytes(void *ptr, size_t length){ char failed = 0; #ifdef WIN32 static HCRYPTPROV prov = 0; if (prov == 0) { if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) { failed = 1; } } if (!failed && !CryptGenRandom(prov, length, ptr)) { failed = 1; } #else int fh; if ((fh = open("/dev/urandom", O_RDONLY)) >= 0 || (fh = open("/dev/random", O_RDONLY)) >= 0) { const ssize_t ret = read(fh, ptr, length); if (ret < 0 || (size_t) ret != length) { failed = 1; } close(fh); } else { failed = 1; } #endif if (failed) { ErrorExit("%s: ERROR: randombytes failed for all possible methods for accessing random data", __local_name); }}
开发者ID:ariosx,项目名称:ossec-hids,代码行数:36,
示例9: memsetbool CEncryptSyncData::InitEncryptHandle(const char * pchrPassWord){ memset(m_chKeyPassWord,0,sizeof(m_chKeyPassWord)); memcpy(m_chKeyPassWord,pchrPassWord,strlen(pchrPassWord)); if(!CryptAcquireContext(&hCryptProv,NULL,NULL,PROV_RSA_FULL,0)) { return false; } if(!CryptCreateHash(hCryptProv,CALG_MD5,0,0,&hHash)) { return false; } if(!CryptHashData(hHash,(BYTE *)m_chKeyPassWord,strlen(m_chKeyPassWord),0)) { return false; } if(!CryptDeriveKey(hCryptProv,ENCRYPT_ALGORITHM, hHash, KEYLENGTH,&hKey)) { return false; } CryptDestroyHash(hHash); hHash = 0; return true;}
开发者ID:guangminghan,项目名称:CyclonicGameEngine,代码行数:24,
示例10: mbedtls_platform_entropy_pollint mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ){ HCRYPTPROV provider; ((void) data); *olen = 0; if( CryptAcquireContext( &provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) { return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) { CryptReleaseContext( provider, 0 ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } CryptReleaseContext( provider, 0 ); *olen = len; return( 0 );}
开发者ID:kiibohd,项目名称:controller,代码行数:24,
示例11: cryptographicallyRandomValuesFromOSvoid cryptographicallyRandomValuesFromOS(unsigned char* buffer, size_t length){#if OS(UNIX) int fd = open("/dev/urandom", O_RDONLY, 0); if (fd < 0) CRASH(); // We need /dev/urandom for this API to work... if (read(fd, buffer, length) != static_cast<ssize_t>(length)) CRASH(); close(fd);#elif OS(WINDOWS) HCRYPTPROV hCryptProv = 0; if (!CryptAcquireContext(&hCryptProv, 0, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) CRASH(); if (!CryptGenRandom(hCryptProv, length, buffer)) CRASH(); CryptReleaseContext(hCryptProv, 0);#else #error "This configuration doesn't have a strong source of randomness." // WARNING: When adding new sources of OS randomness, the randomness must // be of cryptographic quality!#endif}
开发者ID:CannedFish,项目名称:deepin-webkit,代码行数:24,
示例12: GenRandomBytesvoid GenRandomBytes(void* dest, size_t size){#ifdef _WIN32 HCRYPTPROV prov; if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) Sys::Error("CryptAcquireContext failed: %s", Win32StrError(GetLastError())); if (!CryptGenRandom(prov, size, (BYTE*)dest)) Sys::Error("CryptGenRandom failed: %s", Win32StrError(GetLastError())); CryptReleaseContext(prov, 0);#elif defined(__native_client__) size_t bytes_written; if (nacl_secure_random(dest, size, &bytes_written) != 0 || bytes_written != size) Sys::Error("nacl_secure_random failed");#else int fd = open("/dev/urandom", O_RDONLY); if (fd == -1) Sys::Error("Failed to open /dev/urandom: %s", strerror(errno)); if (read(fd, dest, size) != (ssize_t) size) Sys::Error("Failed to read from /dev/urandom: %s", strerror(errno)); close(fd);#endif}
开发者ID:norfenstein,项目名称:unvqx,代码行数:24,
示例13: SetFromPassword/** * * Generate System key from pass phrase -> level 2 * Derives 128-bit value from MD5 * */BOOL SystemKey::SetFromPassword (std::wstring pwd) { HCRYPTPROV hProv; HCRYPTHASH hHash; if (CryptAcquireContext (&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { if (CryptCreateHash (hProv, CALG_MD5, 0, 0, &hHash)) { if (CryptHashData (hHash, (PBYTE)pwd.c_str(), pwd.length() * sizeof(wchar_t), 0)) { DWORD dwHashLen = SYSTEM_KEY_LEN; CryptGetHashParam (hHash, HP_HASHVAL, key, &dwHashLen, 0); dwError = GetLastError(); } CryptDestroyHash (hHash); } else { dwError = GetLastError (); } CryptReleaseContext (hProv, 0); } else { dwError = GetLastError (); } return dwError == ERROR_SUCCESS;}
开发者ID:infosecsmith,项目名称:ntds_decode,代码行数:30,
示例14: getHbootKeyFromBootKeyAndF |