⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00428"></a>00428 <a name="l00429"></a>00429 <span class="keywordtype">bool</span> RSAVerifyFile(<span class="keyword">const</span> <span class="keywordtype">char</span> *pubFilename, <span class="keyword">const</span> <span class="keywordtype">char</span> *messageFilename, <span class="keyword">const</span> <span class="keywordtype">char</span> *signatureFilename)<a name="l00430"></a>00430 {<a name="l00431"></a>00431         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> pubFile(pubFilename, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>);<a name="l00432"></a>00432         <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS&lt;PKCS1v15, SHA&gt;::Verifier</a> pub(pubFile);<a name="l00433"></a>00433 <a name="l00434"></a>00434         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> signatureFile(signatureFilename, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>);<a name="l00435"></a>00435         <span class="keywordflow">if</span> (signatureFile.MaxRetrievable() != pub.SignatureLength())<a name="l00436"></a>00436                 <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00437"></a>00437         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> signature(pub.SignatureLength());<a name="l00438"></a>00438         signatureFile.Get(signature, signature.size());<a name="l00439"></a>00439 <a name="l00440"></a>00440         <a class="code" href="class_signature_verification_filter.html" title="Filter Wrapper for PK_Verifier.">VerifierFilter</a> *verifierFilter = <span class="keyword">new</span> <a class="code" href="class_signature_verification_filter.html" title="Filter Wrapper for PK_Verifier.">VerifierFilter</a>(pub);<a name="l00441"></a>00441         verifierFilter-&gt;<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(signature, pub.SignatureLength());<a name="l00442"></a>00442         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f(messageFilename, <span class="keyword">true</span>, verifierFilter);<a name="l00443"></a>00443 <a name="l00444"></a>00444         <span class="keywordflow">return</span> verifierFilter-&gt;<a class="code" href="class_signature_verification_filter.html#8939c9cdd0f5ed772a8371e20a9bb468">GetLastResult</a>();<a name="l00445"></a>00445 }<a name="l00446"></a>00446 <a name="l00447"></a>00447 <span class="keywordtype">void</span> DigestFile(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename)<a name="l00448"></a>00448 {<a name="l00449"></a>00449         <a class="code" href="class_s_h_a1.html" title="SHA-1">SHA1</a> sha;<a name="l00450"></a>00450         <a class="code" href="class_r_i_p_e_m_d160.html" title="RIPEMD-160">RIPEMD160</a> ripemd;<a name="l00451"></a>00451         <a class="code" href="class_s_h_a256.html" title="implements the SHA-256 standard">SHA256</a> sha256;<a name="l00452"></a>00452 <span class="preprocessor">#ifdef WORD64_AVAILABLE</span><a name="l00453"></a>00453 <span class="preprocessor"></span>        <a class="code" href="class_tiger.html" title="Tiger">Tiger</a> tiger;<a name="l00454"></a>00454         <a class="code" href="class_s_h_a512.html" title="implements the SHA-512 standard">SHA512</a> sha512;<a name="l00455"></a>00455         <a class="code" href="class_whirlpool.html" title="Whirlpool">Whirlpool</a> whirlpool;<a name="l00456"></a>00456         <a class="code" href="classvector__member__ptrs.html">vector_member_ptrs&lt;HashFilter&gt;</a> filters(6);<a name="l00457"></a>00457         filters[0].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(sha));<a name="l00458"></a>00458         filters[1].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(ripemd));<a name="l00459"></a>00459         filters[2].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(tiger));<a name="l00460"></a>00460         filters[3].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(sha256));<a name="l00461"></a>00461         filters[4].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(sha512));<a name="l00462"></a>00462         filters[5].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(whirlpool));<a name="l00463"></a>00463 <span class="preprocessor">#else</span><a name="l00464"></a>00464 <span class="preprocessor"></span>        <a class="code" href="classvector__member__ptrs.html">vector_member_ptrs&lt;HashFilter&gt;</a> filters(3);<a name="l00465"></a>00465         filters[0].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(sha));<a name="l00466"></a>00466         filters[1].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(ripemd));<a name="l00467"></a>00467         filters[2].reset(<span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(sha256));<a name="l00468"></a>00468 <span class="preprocessor">#endif</span><a name="l00469"></a>00469 <span class="preprocessor"></span><a name="l00470"></a>00470         auto_ptr&lt;ChannelSwitch&gt; channelSwitch(<span class="keyword">new</span> <a class="code" href="class_channel_switch.html" title="Route input to different and/or multiple channels based on channel ID.">ChannelSwitch</a>);<a name="l00471"></a>00471         <span class="keywordtype">size_t</span> i;<a name="l00472"></a>00472         <span class="keywordflow">for</span> (i=0; i&lt;filters.size(); i++)<a name="l00473"></a>00473                 channelSwitch-&gt;AddDefaultRoute(*filters[i]);<a name="l00474"></a>00474         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a>(filename, <span class="keyword">true</span>, channelSwitch.release());<a name="l00475"></a>00475 <a name="l00476"></a>00476         <a class="code" href="class_hex_encoder.html" title="Converts given data to base 16.">HexEncoder</a> encoder(<span class="keyword">new</span> <a class="code" href="class_file_sink.html" title="file-based implementation of Sink interface">FileSink</a>(cout), <span class="keyword">false</span>);<a name="l00477"></a>00477         <span class="keywordflow">for</span> (i=0; i&lt;filters.size(); i++)<a name="l00478"></a>00478         {<a name="l00479"></a>00479                 cout &lt;&lt; filters[i]-&gt;AlgorithmName() &lt;&lt; <span class="stringliteral">": "</span>;<a name="l00480"></a>00480                 filters[i]-&gt;TransferTo(encoder);<a name="l00481"></a>00481                 cout &lt;&lt; <span class="stringliteral">"\n"</span>;<a name="l00482"></a>00482         }<a name="l00483"></a>00483 }<a name="l00484"></a>00484 <a name="l00485"></a>00485 <span class="keywordtype">void</span> HmacFile(<span class="keyword">const</span> <span class="keywordtype">char</span> *hexKey, <span class="keyword">const</span> <span class="keywordtype">char</span> *file)<a name="l00486"></a>00486 {<a name="l00487"></a>00487         <a class="code" href="classmember__ptr.html">member_ptr&lt;MessageAuthenticationCode&gt;</a> mac;<a name="l00488"></a>00488         <span class="keywordflow">if</span> (strcmp(hexKey, <span class="stringliteral">"selftest"</span>) == 0)<a name="l00489"></a>00489         {<a name="l00490"></a>00490                 cerr &lt;&lt; <span class="stringliteral">"Computing HMAC/SHA1 value for self test.\n"</span>;<a name="l00491"></a>00491                 mac.<a class="code" href="classmember__ptr.html#0191c833924d93e9093b07bab31010fe">reset</a>(<a class="code" href="fips140_8h.html#766d57f0d6451c714b95ba126258b487">NewIntegrityCheckingMAC</a>());<a name="l00492"></a>00492         }<a name="l00493"></a>00493         <span class="keywordflow">else</span><a name="l00494"></a>00494         {<a name="l00495"></a>00495                 std::string decodedKey;<a name="l00496"></a>00496                 <a class="code" href="class_string_source.html" title="string-based implementation of Source interface">StringSource</a>(hexKey, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a>(<span class="keyword">new</span> <a class="code" href="class_string_sink_template.html" title="Append input to a string object.">StringSink</a>(decodedKey)));<a name="l00497"></a>00497                 mac.<a class="code" href="classmember__ptr.html#0191c833924d93e9093b07bab31010fe">reset</a>(<span class="keyword">new</span> <a class="code" href="class_h_m_a_c.html" title="HMAC">HMAC&lt;SHA1&gt;</a>((<span class="keyword">const</span> byte *)decodedKey.data(), decodedKey.size()));<a name="l00498"></a>00498         }<a name="l00499"></a>00499         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a>(file, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_hash_filter.html" title="Filter Wrapper for HashTransformation.">HashFilter</a>(*mac, <span class="keyword">new</span> <a class="code" href="class_hex_encoder.html" title="Converts given data to base 16.">HexEncoder</a>(<span class="keyword">new</span> <a class="code" href="class_file_sink.html" title="file-based implementation of Sink interface">FileSink</a>(cout))));<a name="l00500"></a>00500 }<a name="l00501"></a>00501 <a name="l00502"></a>00502 <span class="keywordtype">void</span> AES_CTR_Encrypt(<span class="keyword">const</span> <span class="keywordtype">char</span> *hexKey, <span class="keyword">const</span> <span class="keywordtype">char</span> *hexIV, <span class="keyword">const</span> <span class="keywordtype">char</span> *infile, <span class="keyword">const</span> <span class="keywordtype">char</span> *outfile)<a name="l00503"></a>00503 {<a name="l00504"></a>00504         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> key = HexDecodeString(hexKey);<a name="l00505"></a>00505         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> iv = HexDecodeString(hexIV);<a name="l00506"></a>00506         <a class="code" href="struct_c_t_r___mode.html" title="CTR mode.">CTR_Mode&lt;AES&gt;::Encryption</a> aes(key, key.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>(), iv);<a name="l00507"></a>00507         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a>(infile, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_stream_transformation_filter.html" title="Filter Wrapper for StreamTransformation.">StreamTransformationFilter</a>(aes, <span class="keyword">new</span> <a class="code" href="class_file_sink.html" title="file-based implementation of Sink interface">FileSink</a>(outfile)));<a name="l00508"></a>00508 }<a name="l00509"></a>00509 <a name="l00510"></a>00510 <span class="keywordtype">string</span> EncryptString(<span class="keyword">const</span> <span class="keywordtype">char</span> *instr, <span class="keyword">const</span> <span class="keywordtype">char</span> *passPhrase)<a name="l00511"></a>00511 {<a name="l00512"></a>00512         <span class="keywordtype">string</span> outstr;<a name="l00513"></a>00513 <a name="l00514"></a>00514         <a class="code" href="class_default_encryptor_with_m_a_c.html" title="Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1.">DefaultEncryptorWithMAC</a> encryptor(passPhrase, <span class="keyword">new</span> <a class="code" href="class_hex_encoder.html" title="Converts given data to base 16.">HexEncoder</a>(<span class="keyword">new</span> <a class="code" href="class_string_sink_template.html" title="Append input to a string object.">StringSink</a>(outstr)));<a name="l00515"></a>00515         encryptor.Put((byte *)instr, strlen(instr));<a name="l00516"></a>00516         encryptor.MessageEnd();<a name="l00517"></a>00517 <a name="l00518"></a>00518         <span class="keywordflow">return</span> outstr;<a name="l00519"></a>00519 }<a name="l00520"></a>00520 <a name="l00521"></a>00521 <span class="keywordtype">string</span> DecryptString(<span class="keyword">const</span> <span class="keywordtype">char</span> *instr, <span class="keyword">const</span> <span class="keywordtype">char</span> *passPhrase)<a name="l00522"></a>00522 {<a name="l00523"></a>00523         <span class="keywordtype">string</span> outstr;<a name="l00524"></a>00524 <a name="l00525"></a>00525         <a class="code" href="class_hex_decoder.html" title="Decode base 16 data back to bytes.">HexDecoder</a> decryptor(<span class="keyword">new</span> <a class="code" href="class_default_decryptor_with_m_a_c.html" title="Password-Based Decryptor using DES-EDE2 and HMAC/SHA-1.">DefaultDecryptorWithMAC</a>(passPhrase, <span class="keyword">new</span> <a class="code" href="class_string_sink_template.html" title="Append input to a string object.">StringSink</a>(outstr)));<a name="l00526"></a>00526         decryptor.Put((byte *)instr, strlen(instr));<a name="l00527"></a>00527         decryptor.MessageEnd();<a name="l00528"></a>00528 <a name="l00529"></a>00529         <span class="keywordflow">return</span> outstr;<a name="l00530"></a>00530 }<a name="l00531"></a>00531 <a name="l00532"></a>00532 <span class="keywordtype">void</span> EncryptFile(<span class="keyword">const</span> <span class="keywordtype">char</span> *in, <span class="keyword">const</span> <span class="keywordtype">char</span> *out, <span class="keyword">const</span> <span class="keywordtype">char</span> *passPhrase)<a name="l00533"></a>00533 {<a name="l00534"></a>00534         <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f(in, <span class="keyword">true</span>, <span class="keyword">new</span> <a class="code" href="class_default_encryptor_with_m_a_c.html" title="Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1.">DefaultEncryptorWithMAC</a>(passPhrase, <span class="keyword">new</span> <a class="code" href="class_file_sink.html" title="file-based implementation of Sink interface">FileSink</a>(out)));<a name="l00535"></a>00535 }<a name="l00536"></a>00536 <a name="l00537"></a>00537 <span class="keywordtype">void</span> DecryptFile(<span class="keyword">const</span> <span class="keywordtype">char</span> *in, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -