当前位置: 首页>>代码示例>>C++>>正文


C++ CryptDestroyHash函数代码示例

本文整理汇总了C++中CryptDestroyHash函数的典型用法代码示例。如果您正苦于以下问题:C++ CryptDestroyHash函数的具体用法?C++ CryptDestroyHash怎么用?C++ CryptDestroyHash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CryptDestroyHash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Create_AES256_KeyBLOB

BOOL Create_AES256_KeyBLOB(
  HCRYPTPROV    prov,               // CSP
  unsigned char *pbPassword,        // input (Password for Key and IV)
  DWORD         cbPassword,         // input (length)
  unsigned char *pbSalt,            // input (Salt for Key and IV)
  DWORD         cbSalt,             // input (length 8 or 16)
  AES_256_KEY_BLOB  *blob,          // output
  unsigned char pbIV[16]            // output (length fixed 16)
)
{
  BOOL bStatus = FALSE;
  DWORD dwError = 0;
  EVERIFY(prov && pbPassword && pbSalt && blob && pbIV);
  const int N = 3;
  BYTE hashdata[N][HASH_MD5_LEN];
  for(int i = 0; i < N; i++){
    HCRYPTHASH hash = NULL;
    EVERIFY(CryptCreateHash(prov, CALG_MD5, 0, 0, &hash));
    BYTE hashwork[HASH_MD5_LEN * 64];
    EVERIFY(HASH_MD5_LEN + cbPassword + cbSalt <= sizeof(hashwork));
    DWORD hashlen; // must get with HP_HASHVAL (not use HP_HASHSIZE)
    if(!i) hashlen = 0;
    else CopyMemory(hashwork, hashdata[i - 1], hashlen = HASH_MD5_LEN);
    CopyMemory(hashwork + hashlen, pbPassword, cbPassword);
    CopyMemory(hashwork + hashlen + cbPassword, pbSalt, cbSalt);
    EVERIFY(CryptHashData(hash, hashwork, hashlen + cbPassword + cbSalt, 0));
    EVERIFY(CryptGetHashParam(hash, HP_HASHVAL, NULL, &hashlen, 0));
    EVERIFY(hashlen == HASH_MD5_LEN);
    EVERIFY(CryptGetHashParam(hash, HP_HASHVAL, hashdata[i], &hashlen, 0));
    if(hash) EVERIFY(CryptDestroyHash(hash));
  }
  blob->hdr.bType = PLAINTEXTKEYBLOB;
  blob->hdr.bVersion = CUR_BLOB_VERSION;
  blob->hdr.reserved = 0;
  blob->hdr.aiKeyAlg = CALG_AES_256;
  blob->cbKeySize = 32; // sizeof(blob->pbDerivedKey) is the size of pointer
  CopyMemory(blob->pbDerivedKey, hashdata[0], HASH_MD5_LEN);
  CopyMemory(blob->pbDerivedKey + HASH_MD5_LEN, hashdata[1], HASH_MD5_LEN);
  CopyMemory(pbIV, hashdata[2], HASH_MD5_LEN);
  bStatus = TRUE;

done:
  return bStatus;
}
开发者ID:HatsuneMiku,项目名称:ssxcopy,代码行数:44,代码来源:AES256_KeyBLOB.cpp

示例2: DWORD

std::string CStringUtils::Encrypt(const std::string& s, const std::string& password)
{
    std::string encryptedstring;
    HCRYPTPROV hProv = NULL;
    // Get handle to user default provider.
    if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
    {
        HCRYPTHASH hHash = NULL;
        // Create hash object.
        if (CryptCreateHash(hProv, CALG_SHA_512, 0, 0, &hHash))
        {
            // Hash password string.
            DWORD dwLength = DWORD(sizeof(WCHAR)*password.size());
            if (CryptHashData(hHash, (BYTE *)password.c_str(), dwLength, 0))
            {
                // Create block cipher session key based on hash of the password.
                HCRYPTKEY hKey = NULL;
                if (CryptDeriveKey(hProv, CALG_AES_256, hHash, CRYPT_EXPORTABLE, &hKey))
                {
                    // Determine number of bytes to encrypt at a time.
                    std::string starname = "*";
                    starname += s;

                    dwLength = (DWORD)starname.size();
                    std::unique_ptr<BYTE[]> buffer(new BYTE[dwLength + 1024]);
                    memcpy(buffer.get(), starname.c_str(), dwLength);
                    // Encrypt data
                    if (CryptEncrypt(hKey, 0, true, 0, buffer.get(), &dwLength, dwLength + 1024))
                    {
                        encryptedstring = CStringUtils::ToHexString(buffer.get(), dwLength);
                    }
                    CryptDestroyKey(hKey);  // Release provider handle.
                }
            }
            CryptDestroyHash(hHash);
        }
        CryptReleaseContext(hProv, 0);
    }
    else
        DebugBreak();
    return encryptedstring;

}
开发者ID:Kasper8660,项目名称:tortoisesvn,代码行数:43,代码来源:StringUtils.cpp

示例3: CryptDestroyHash

bool CCommonUtils::CalcHash(ALG_ID hashType, const BYTE* lpData, DWORD dwLen, BYTE* lpHash, DWORD dwHashSize)
{
    HCRYPTPROV hProv = NULL;
    HCRYPTHASH hHash = NULL;
    bool bRet = false;

    if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) 
    {
        goto endFunction;
    }

    if(!CryptCreateHash(hProv, hashType, 0, 0, &hHash)) 
    {
        goto endFunction;
    }

    if(!CryptHashData(hHash, lpData, dwLen, 0)) 
    {
        goto endFunction;
    }

    if(!CryptGetHashParam(hHash, HP_HASHVAL, lpHash, &dwHashSize, 0))
    {
        goto endFunction;
    }

    bRet = true;

endFunction:

    if(hHash) 
    {
        CryptDestroyHash(hHash);
    }

    if(hProv) 
    {
        CryptReleaseContext(hProv, 0);
    }

    return bRet;
}
开发者ID:johnjohnsp1,项目名称:AxHell,代码行数:42,代码来源:CommonUtils.cpp

示例4: compare_sha1

static BOOL compare_sha1(void *data, unsigned int pitch, unsigned int bpp,
        unsigned int w, unsigned int h, const char *ref_sha1)
{
    static const char hex_chars[] = "0123456789abcdef";
    HCRYPTPROV provider;
    BYTE hash_data[20];
    HCRYPTHASH hash;
    unsigned int i;
    char sha1[41];
    BOOL ret;

    ret = CryptAcquireContextW(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
    ok(ret, "Failed to acquire crypt context.\n");
    ret = CryptCreateHash(provider, CALG_SHA1, 0, 0, &hash);
    ok(ret, "Failed to create hash.\n");

    for (i = 0; i < h; ++i)
    {
        if (!(ret = CryptHashData(hash, (BYTE *)data + pitch * i, w * bpp, 0)))
            break;
    }
    ok(ret, "Failed to hash data.\n");

    i = sizeof(hash_data);
    ret = CryptGetHashParam(hash, HP_HASHVAL, hash_data, &i, 0);
    ok(ret, "Failed to get hash value.\n");
    ok(i == sizeof(hash_data), "Got unexpected hash size %u.\n", i);

    ret = CryptDestroyHash(hash);
    ok(ret, "Failed to destroy hash.\n");
    ret = CryptReleaseContext(provider, 0);
    ok(ret, "Failed to release crypt context.\n");

    for (i = 0; i < 20; ++i)
    {
        sha1[i * 2] = hex_chars[hash_data[i] >> 4];
        sha1[i * 2 + 1] = hex_chars[hash_data[i] & 0xf];
    }
    sha1[40] = 0;

    return !strcmp(ref_sha1, (char *)sha1);
}
开发者ID:VOID001,项目名称:wine-void,代码行数:42,代码来源:d2d1.c

示例5: create_crypthash_ptr

	inline crypthash_ptr_t create_crypthash_ptr(HCRYPTPROV hProv,	ALG_ID Algid,	HCRYPTKEY hKey,	DWORD dwFlags)
	{
		HCRYPTHASH tmp;
		
		if( !CryptCreateHash( hProv, Algid, hKey, dwFlags, &tmp ) )
		{
			DWORD const errc = GetLastError();
			STCRYPT_THROW_EXCEPTION( exception::cryptoapi_error() << exception::cryptoapi_einfo(errc) );
		}

		std::auto_ptr<HCRYPTHASH> hcrypthash_mem;
		try {
			hcrypthash_mem.reset(new HCRYPTHASH(tmp));
		}catch(...){
			BOOL const r = CryptDestroyHash(tmp); assert(r);
			throw;
		}

		return crypthash_ptr_t  ( hcrypthash_mem.release(), delete_HCRYPTHASH );
	}
开发者ID:abelepereira,项目名称:stcrypt,代码行数:20,代码来源:util-raii-helpers-crypt.hpp

示例6: SignHashString

///////////////////////////////////////////////////////////////////////////////////////
// Function: SignHashString
// Description: hash string signing
/////////////////////////////////////////////////////////////////////////////////////////
BOOL SignHashString(
/////////////////////////////////////////////////////////////////////////////////////////
    HCRYPTPROV hProv,
    HCRYPTKEY hPubKey,
    DWORD dwKeySpec,
    LPBYTE pbHash,
    LPBYTE pbSignature,
    DWORD *dwSignature)
{
    HCRYPTHASH hHash = NULL;

    BOOL fResult;
    BOOL fReturn = FALSE;

    __try
    {
        // Create Hash
        fResult = CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash);
        if (!fResult)
            __leave;



        // Set Hash
        fResult=CryptSetHashParam(hHash,HP_HASHVAL,pbHash,0);


        fResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, pbSignature, dwSignature);
        if (!fResult)
            __leave;

        fReturn = TRUE;
    }

    __finally
    {
        if (hHash != NULL) CryptDestroyHash(hHash);
    }

    return fReturn;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:45,代码来源:Sign.cpp

示例7: compareHash

int compareHash(LPSTR inputpassword, LPSTR readhash)
{
	
	HCRYPTPROV hProv;
	HCRYPTHASH crypt_hash;
	DWORD hashlen = MD5_LEN;
	BYTE md5hash[MD5_LEN] = {0};
	char hashbyte[8] = {0};
	char hashtext[32] = {0};

	//Initialize crypto
	if (!CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT))
		return 1;

	//Initialize Hashing algorithm
	if (!CryptCreateHash(hProv,CALG_MD5,0,0,&crypt_hash))
		return 1;

	//Hash the plaintext data
	if (!CryptHashData(crypt_hash,(const BYTE*)inputpassword,lstrlen(inputpassword),0))
		return 1;

	//Create the 16 byte hash
	if (!CryptGetHashParam(crypt_hash,HP_HASHVAL,md5hash,&hashlen,0))
		return 1;
	
	//convert the byte hash to text hash
	for (int i = 0;i < MD5_LEN; i++)
	{
		sprintf(hashbyte,"%02x",md5hash[i]);
		strncat(hashtext,hashbyte,32);
	}

		if (lstrcmp(hashtext,readhash) != 0)
			return 2;

	CryptDestroyHash(crypt_hash);
	CryptReleaseContext(hProv, 0);

	return 0;
}
开发者ID:pzinwai,项目名称:KioskClientApp,代码行数:41,代码来源:main.c

示例8: checkSig

void checkSig(unsigned char *tucHashBuf,
			  unsigned char *tucSignature, DWORD dwSignatureLen,
			  unsigned char *tucPubKeyBlob, DWORD dwPubKeyBlobLen)
{
	HCRYPTPROV hProv;
	HCRYPTKEY hPubKey;
	HCRYPTHASH hHash;
	DWORD err;
	int errors = 0;

	if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
		ERR_LOG_RET("CryptAcquireContext()");

	if (!CryptImportKey(hProv, tucPubKeyBlob, dwPubKeyBlobLen, 0, 0, &hPubKey))
		ERR_LOG_RET("CryptImportKey()");

	if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
		ERR_LOG_RET("CryptCreateHash(CALG_MD5)");

	if (!CryptSetHashParam(hHash, HP_HASHVAL, tucHashBuf, 0))
		ERR_LOG_RET("CryptSetHashParam(HP_HASHVAL)");

	if (!CryptVerifySignature(hHash, tucSignature, dwSignatureLen, hPubKey, NULL, 0))
	{
		err = GetLastError();
		printf("ERR (line %d): CryptVerifySignature() returned %s (0x%0x)\n", __LINE__, e2str(err), err);
		errors++;
	}

	if (!CryptDestroyHash(hHash))
		ERR_LOG_RET("CryptDestroyHash()");

	if (!CryptDestroyKey(hPubKey))
		ERR_LOG_RET("CryptDestroyKey()");

	CryptReleaseContext(hProv, 0);

done:
	return;
}
开发者ID:12019,项目名称:svn.gov.pt,代码行数:40,代码来源:main.c

示例9: CryptCreateHash

bool mod_hash::decryptHash(wstring * hash, BYTE * hBootKey, USER_V * userV, SAM_ENTRY * encHash, DWORD rid, bool isNtlm)
{
	bool reussite = false;
	unsigned char ntpassword[] = "NTPASSWORD";
	unsigned char lmpassword[] = "LMPASSWORD";

	BYTE obfkey[0x10];
	BYTE mes2CleDES[0x10];

	if(encHash->lenght == 0x10 + 4)
	{
		HCRYPTPROV hCryptProv = NULL;
		HCRYPTHASH hHash = NULL;
		if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
		{
			BYTE md5hash[0x10] = {0};
			DWORD dwHashDataLen = 0x10;
			CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash);
			CryptHashData(hHash, hBootKey, 0x10, 0);
			CryptHashData(hHash, (BYTE *) &rid, sizeof(rid), 0);
			CryptHashData(hHash, isNtlm ? ntpassword : lmpassword, isNtlm ? sizeof(ntpassword) : sizeof(lmpassword), 0);
			CryptGetHashParam(hHash, HP_HASHVAL, md5hash, &dwHashDataLen, 0);
			CryptDestroyHash(hHash);
			
			CryptReleaseContext(hCryptProv, 0);

			if(mod_crypto::genericDecrypt(&(userV->datas) + encHash->offset + 4, 0x10, md5hash, 0x10, CALG_RC4, obfkey, 0x10))
			{
				sid_to_key1(rid, mes2CleDES);
				sid_to_key2(rid, mes2CleDES + 8);
			
				reussite = mod_crypto::genericDecrypt(obfkey + 0, sizeof(obfkey) / 2, mes2CleDES + 0, sizeof(mes2CleDES) / 2, CALG_DES) &&
					mod_crypto::genericDecrypt(obfkey + 8, sizeof(obfkey) / 2, mes2CleDES + 8, sizeof(mes2CleDES) / 2, CALG_DES);
			}
		}
	}
	hash->assign(reussite ? mod_text::stringOfHex(obfkey, sizeof(obfkey)) : L"");

	return reussite;
}
开发者ID:DarkGreising,项目名称:mimikatz-en,代码行数:40,代码来源:mod_hash.cpp

示例10: getCertificateHash

static CString getCertificateHash(HCRYPTPROV hCryptProv, ALG_ID algId, BYTE* certificate, size_t len)
{
	CString readable = _T("unknown");
	std::unique_ptr<BYTE[]> pHash(nullptr);
	HCRYPTHASH hHash = NULL;

	if (!hCryptProv)
		goto finish;

	if (!CryptCreateHash(hCryptProv, algId, 0, 0, &hHash))
		goto finish;

	if (!CryptHashData(hHash, certificate, (DWORD)len, 0))
		goto finish;

	DWORD hashLen;
	DWORD hashLenLen = sizeof(DWORD);
	if (!CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE *)&hashLen, &hashLenLen, 0))
		goto finish;

	pHash.reset(new BYTE[hashLen]);
	if (!CryptGetHashParam(hHash, HP_HASHVAL, pHash.get(), &hashLen, 0))
		goto finish;

	readable.Empty();
	for (const BYTE* it = pHash.get(); it < pHash.get() + hashLen; ++it)
	{
		CString tmp;
		tmp.Format(L"%02X", *it);
		if (!readable.IsEmpty())
			readable += L":";
		readable += tmp;
	}

finish:
	if (hHash)
		CryptDestroyHash(hHash);

	return readable;
}
开发者ID:545546460,项目名称:TortoiseGit,代码行数:40,代码来源:CheckCertificateDlg.cpp

示例11: hash

/**
 * Calculates the hash of the given message and hashtype
 */
int hash(int hashtype, const unsigned char *src, unsigned int srclen,
         unsigned char *dest, unsigned int *destlen)
{
    HCRYPTHASH hash;
    ALG_ID alg;
    int hashlen, rval;
    DWORD _destlen;

    hashlen = get_hash_len(hashtype);
    alg = get_hash(hashtype);
    if (alg == 0) {
        log0(0, 0, 0, "Invalid hashtype");
        return 0;
    }

    if (!CryptCreateHash(base_prov, alg, 0, 0, &hash)) {
        mserror("CryptCreateHash failed");
        return 0;
    }
    if (!CryptHashData(hash, src, srclen, 0)) {
        mserror("CryptHashData failed");
        rval = 0;
        goto end;
    }
    _destlen = hashlen;
    if (!CryptGetHashParam(hash, HP_HASHVAL, dest, &_destlen, 0)) {
        mserror("CryptGetHashParam failed");
        rval = 0;
        goto end;
    }
    *destlen = _destlen;
    rval = 1;

end:
    if (!CryptDestroyHash(hash)) {
        mserror("CryptDestroyHash failed");
    }
    return rval;
}
开发者ID:PumpkinSpace,项目名称:uftp,代码行数:42,代码来源:encrypt_cryptoapi.c

示例12: DeriveKey

// Derive an encryption key from a user-supplied buffer
static HCRYPTKEY DeriveKey(const void *pKey, int nKeyLen)
{
  HCRYPTHASH hHash = 0;
  HCRYPTKEY  hKey;

  if (!pKey || !nKeyLen) return 0;

  if (!InitializeProvider())
  {
    return MAXDWORD;
  }

  if (CryptCreateHash(g_hProvider, CALG_SHA1, 0, 0, &hHash))
  {
    if (CryptHashData(hHash, (LPBYTE)pKey, nKeyLen, 0))
    {
      CryptDeriveKey(g_hProvider, CALG_RC4, hHash, 0, &hKey);
    }
    CryptDestroyHash(hHash);
  }  
  return hKey;
}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:23,代码来源:crypt.c

示例13: 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 void
exsltCryptoCryptoApiHash (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:Ashod,项目名称:WinCairoRequirements,代码行数:34,代码来源:crypto.c

示例14: sizeof

bool mod_hash::getHbootKeyFromBootKeyAndF(BYTE hBootKey[0x10], BYTE bootKey[0x10], BYTE * AccountsF)
{
	bool reussite = false;
	unsigned char qwe[] = "[email protected]#$%^&*()qwertyUIOPAzxcvbnmQQQQQQQQQQQQ)(*@&%";
	unsigned char num[] = "0123456789012345678901234567890123456789";

	HCRYPTPROV hCryptProv = NULL;
	HCRYPTHASH hHash = NULL;
	if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
	{
		BYTE md5hash[0x10] = {0};
		DWORD dwHashDataLen = sizeof(md5hash);
		CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash);
		CryptHashData(hHash, AccountsF + 0x70, 0x10, 0);
		CryptHashData(hHash, qwe, sizeof(qwe), 0);
		CryptHashData(hHash, bootKey, 0x10, 0);
		CryptHashData(hHash, num, sizeof(num), 0);
		CryptGetHashParam(hHash, HP_HASHVAL, md5hash, &dwHashDataLen, 0);
		CryptDestroyHash(hHash);
		CryptReleaseContext(hCryptProv, 0);
		reussite = mod_crypto::genericDecrypt(AccountsF + 0x80, 0x10, md5hash, 0x10, CALG_RC4, hBootKey, 0x10);
	}
	return reussite;
}
开发者ID:DarkGreising,项目名称:mimikatz-en,代码行数:24,代码来源:mod_hash.cpp

示例15: sizeof

/**
 *
 *  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,代码来源:systemkey.cpp


注:本文中的CryptDestroyHash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。