<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Cryptographic_API</id>
	<title>Cryptographic API - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Cryptographic_API"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Cryptographic_API&amp;action=history"/>
	<updated>2026-06-26T11:37:31Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=Cryptographic_API&amp;diff=444038&amp;oldid=prev</id>
		<title>imported&gt;LoreLiu 来自 2024年12月7日 (六) 06:08</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Cryptographic_API&amp;diff=444038&amp;oldid=prev"/>
		<updated>2024-12-07T06:08:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{noteTA|G1=IT}}&amp;#039;&amp;#039;&amp;#039;Cryptographic API&amp;#039;&amp;#039;&amp;#039; (CryptoAPI) 是微軟在 Windows 作業系統中添加的密碼編譯機能，作為資料加密與解密功能的重要基礎，CryptoAPI 支援同步，非同步的金鑰加密處理，以及作業系統中的[[數位憑證]] 的管理工作。从[[Windows NT 4.0]]引入此功能，并在以后版本的操作系统中不断增强。&lt;br /&gt;
&lt;br /&gt;
目前的 CryptoAPI 支援下列工作&amp;lt;ref&amp;gt;{{Cite web |url=http://msdn.microsoft.com/en-us/library/aa380239(VS.85).aspx |title=CryptoAPI System Architecture |accessdate=2008-09-01 |archive-date=2008-11-08 |archive-url=https://web.archive.org/web/20081108021813/http://msdn.microsoft.com/en-us/library/aa380239(VS.85).aspx |dead-url=no }}&amp;lt;/ref&amp;gt;：&lt;br /&gt;
&lt;br /&gt;
* 基礎[[密碼學]]函數。&lt;br /&gt;
** 內文函數 (Context function)。&lt;br /&gt;
** 金鑰產生函數 (Key generation function)。&lt;br /&gt;
** 金鑰交換函數 (Key Exchange function)。&lt;br /&gt;
* 憑證編碼與解碼函數（支援[[雜湊]]功能）。&lt;br /&gt;
* 憑證儲存函數。&lt;br /&gt;
* 簡單訊息函數。&lt;br /&gt;
** 加密與解密訊息與資料。&lt;br /&gt;
** 對訊息與資料進行簽章。&lt;br /&gt;
** 對收到的訊息與相關資料進行數位簽章驗證的檢查。&lt;br /&gt;
* 低階訊息函數。&lt;br /&gt;
&lt;br /&gt;
由於 CryptoAPI 使用上過於複雜，因此微軟另外為 CryptoAPI 開發更為容易使用的 [[CAPICOM]] 元件&amp;lt;ref&amp;gt;{{Cite web |url=http://msdn.microsoft.com/en-us/library/aa380260(VS.85).aspx |title=Cryptography, CryptoAPI, and CAPICOM |accessdate=2008-09-01 |archive-date=2008-10-26 |archive-url=https://web.archive.org/web/20081026130832/http://msdn.microsoft.com/en-us/library/aa380260(VS.85).aspx |dead-url=no }}&amp;lt;/ref&amp;gt;，以及 [[数据保护API|Data Protection API]]。从Windows Vista开始，推出了新一代密码学API  [[Cryptography API: Next Generation]]。&lt;br /&gt;
==例子==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;wincrypt.h&amp;gt;&lt;br /&gt;
#include &amp;lt;wintrust.h&amp;gt;&lt;br /&gt;
#pragma comment(lib, &amp;quot;crypt32.lib&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;atlstr.h&amp;gt;&lt;br /&gt;
bool GetHash(int hash_type, CString&amp;amp; hash_result, CString&amp;amp; hash_message)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	HCRYPTPROV hCryptProv;&lt;br /&gt;
	HCRYPTHASH hCryptHash;&lt;br /&gt;
&lt;br /&gt;
	/*Note that you will get the error such as ‘Invalid Algorithm Specified’ (Error Code: 0x80090008) when you try to replace the algorithm with CALG_SHA256, CALG_SHA384  or CALG_SHA512. Because these algorithms are not supported by Microsoft Base Cryptography Provider ( PROV_RSA_FULL ).   To fix this problem you need to use the provider as PROV_RSA_AES (Microsoft Enhanced RSA and AES Cryptographic Provider) in the  CryptAcquireContext function instead of PROV_RSA_FULL.*/&lt;br /&gt;
	if (!CryptAcquireContext(&amp;amp;hCryptProv, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, 0))&lt;br /&gt;
		                    //&amp;amp;hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))&lt;br /&gt;
	{&lt;br /&gt;
		unsigned int e = GetLastError();&lt;br /&gt;
		CString str;&lt;br /&gt;
		str.Format(&amp;quot;创建CSP容器出错！错误代码为:%x！&amp;quot;, e);&lt;br /&gt;
		MessageBox(NULL, str, &amp;quot;出错啦!&amp;quot;, MB_OK | MB_ICONERROR);&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!CryptCreateHash(hCryptProv, hash_type, 0, 0, &amp;amp;hCryptHash))&lt;br /&gt;
	{&lt;br /&gt;
		DWORD e = GetLastError();&lt;br /&gt;
		CString str;&lt;br /&gt;
		str.Format(&amp;quot;创建哈希句柄出错！错误代码为:%x！&amp;quot;, e);&lt;br /&gt;
		MessageBox(NULL, str, &amp;quot;出错啦!&amp;quot;, MB_OK | MB_ICONERROR);&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!CryptHashData(hCryptHash, (BYTE*)hash_message.GetBuffer(), hash_message.GetLength(), 0))&lt;br /&gt;
	{&lt;br /&gt;
		int e = GetLastError();&lt;br /&gt;
		CString str;&lt;br /&gt;
		str.Format(&amp;quot;计算哈希值出错！错误代码为:%d！&amp;quot;, e);&lt;br /&gt;
		MessageBox(NULL, str, &amp;quot;出错啦!&amp;quot;, MB_OK | MB_ICONERROR);&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	char hash_data[512];&lt;br /&gt;
	DWORD hash_len = 512;&lt;br /&gt;
	if (!CryptGetHashParam(hCryptHash, HP_HASHVAL, (BYTE*)hash_data, &amp;amp;hash_len, 0))&lt;br /&gt;
	{&lt;br /&gt;
		int e = GetLastError();&lt;br /&gt;
		CString str;&lt;br /&gt;
		str.Format(&amp;quot;获取哈希值出错！错误代码为:%d！&amp;quot;, e);&lt;br /&gt;
		MessageBox(NULL, str, &amp;quot;出错啦!&amp;quot;, MB_OK | MB_ICONERROR);&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	char hash_hex[512];&lt;br /&gt;
	for (unsigned int i = 0; i &amp;lt;= hash_len - 1; i++)&lt;br /&gt;
	{&lt;br /&gt;
		int hash_bit = hash_data[i];&lt;br /&gt;
		int first = (hash_bit &amp;amp; 0xf0) &amp;gt;&amp;gt; 4;&lt;br /&gt;
		int second = hash_bit &amp;amp; 0x0f;&lt;br /&gt;
		char tmp[2];&lt;br /&gt;
		_itoa(first, tmp, 16);&lt;br /&gt;
		hash_hex[i * 2] = tmp[0];&lt;br /&gt;
		_itoa(second, tmp, 16);&lt;br /&gt;
		hash_hex[i * 2 + 1] = tmp[0];&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	hash_hex[hash_len * 2] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	hash_result.Format(&amp;quot;%s&amp;quot;, hash_hex);&lt;br /&gt;
	CryptDestroyHash(hCryptHash);&lt;br /&gt;
	CryptReleaseContext(hCryptProv, NULL);&lt;br /&gt;
	return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== 參考資料 ==&lt;br /&gt;
&amp;lt;div class=&amp;quot;references-small&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Microsoft APIs}}&lt;br /&gt;
&lt;br /&gt;
[[Category:微軟]]&lt;br /&gt;
[[Category:Windows API]]&lt;br /&gt;
[[Category:網路安全]]&lt;/div&gt;</summary>
		<author><name>imported&gt;LoreLiu</name></author>
	</entry>
</feed>