﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-学以致用-专注于流媒体与网络编程开发</title><link>http://www.cppblog.com/msopengl/</link><description>细微决定成败</description><language>zh-cn</language><lastBuildDate>Sat, 11 Apr 2026 14:31:06 GMT</lastBuildDate><pubDate>Sat, 11 Apr 2026 14:31:06 GMT</pubDate><ttl>60</ttl><item><title>#error Need to include strsafe.h after tchar.h错误解决办法</title><link>http://www.cppblog.com/msopengl/archive/2011/10/18/158615.html</link><dc:creator>jemmyLiu</dc:creator><author>jemmyLiu</author><pubDate>Tue, 18 Oct 2011 06:39:00 GMT</pubDate><guid>http://www.cppblog.com/msopengl/archive/2011/10/18/158615.html</guid><wfw:comment>http://www.cppblog.com/msopengl/comments/158615.html</wfw:comment><comments>http://www.cppblog.com/msopengl/archive/2011/10/18/158615.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/msopengl/comments/commentRss/158615.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/msopengl/services/trackbacks/158615.html</trackback:ping><description><![CDATA[<div><p>在做DX编程时项目中会遇到上面的错误</p><p>解决办法：</p><p>#include &lt;tchar.h&gt;<br /> #define _STRSAFE_H_INCLUDED_<br /> #define VC_EXTRALEAN&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Exclude rarely-used stuff from Windows headers<br /> #define _WIN32_WINNT 0x0501</p><p>即tchar.h头声明一定要置前&nbsp;&nbsp;&nbsp; 对于高版本的编译器要设置WINNT大于或等于501而非400</p>希望对大家有帮助</div><img src ="http://www.cppblog.com/msopengl/aggbug/158615.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/msopengl/" target="_blank">jemmyLiu</a> 2011-10-18 14:39 <a href="http://www.cppblog.com/msopengl/archive/2011/10/18/158615.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#读取WM短信邮件</title><link>http://www.cppblog.com/msopengl/archive/2011/07/06/150313.html</link><dc:creator>jemmyLiu</dc:creator><author>jemmyLiu</author><pubDate>Wed, 06 Jul 2011 09:14:00 GMT</pubDate><guid>http://www.cppblog.com/msopengl/archive/2011/07/06/150313.html</guid><wfw:comment>http://www.cppblog.com/msopengl/comments/150313.html</wfw:comment><comments>http://www.cppblog.com/msopengl/archive/2011/07/06/150313.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/msopengl/comments/commentRss/150313.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/msopengl/services/trackbacks/150313.html</trackback:ping><description><![CDATA[邮件Google一下  应该就是<strong><br />System.Object</strong><br />  <strong>Microsoft.WindowsMobile.PocketOutlook.Message</strong><br />    
<font color="#ff3300"><a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.emailmessage.aspx">Microsoft.WindowsMobile.PocketOutlook.EmailMessage</a></font><br />    
				<a href="http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.smsmessage.aspx">Microsoft.WindowsMobile.PocketOutlook.SmsMessage</a><br /><br />C#方式读取似乎很简单<br />引自:http://kb.cnblogs.com/a/1450367/<br /><h1 class="contents_header"><font size="2">WM短信读取(C#)</font></h1><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">采用DataGrid现实<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">读取收件箱内信息</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> button1_Click(</span><span style="color: rgb(0, 0, 255);">object</span><span style="color: rgb(0, 0, 0);"> sender, EventArgs e)<br />        {<br />            DataTable mydt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataTable();<br />            mydt.TableName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">InBox</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderAddress</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Subject</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(DateTime)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(DateTime)));<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (NetMAPI.MAPIInit())<br />            {<br /><br />                NetMAPI mapi </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> NetMAPI();<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.Login())<br />                {<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.OpenMessageStore())<br />                    {<br />  <br />                        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.OpenInbox())<br />                        {<br /><br />                            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.GetContents())<br />                            {<br />                                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> count </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mapi.GetRowCounts();<br />                                SmsMessage msg;<br />                                StringBuilder s </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringBuilder(</span><span style="color: rgb(0, 0, 0);">140</span><span style="color: rgb(0, 0, 0);">);<br />                                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                                DataRow dr;<br />                                </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (mapi.GetNextMessage(</span><span style="color: rgb(0, 0, 255);">out</span><span style="color: rgb(0, 0, 0);"> msg, </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">))<br />                                {<br />                                    i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">;<br />                                    <br />                                    dr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mydt.NewRow();<br />                                    <br />                                    msg.GetSenderName(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">MessageBox.Show(s.ToString());</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                                    msg.GetSenderEmail(s);<br />      <br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderAddress</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">MessageBox.Show(aa);<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">MessageBox.Show(s.ToString());</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                                    msg.GetSubject(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Subject</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    </span><span style="color: rgb(0, 128, 0);">/**/</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">/MessageBox.Show(s.ToString());</span><span style="color: rgb(128, 128, 128);"><br /></span><span style="color: rgb(0, 0, 0);">                                    msg.GetSubmitTime(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    msg.GetReceivedTime(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    msg.Dispose();<br />                                    mydt.Rows.Add(dr);<br />                                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (i </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> count </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />                                    {<br />                                        </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                                    }<br /><br />                                }<br /><br />                            }<br />                        }<br /><br />                    }<br />                    <br />                    mapi.Logout();<br />                }<br />            }<br />            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />            {<br />                MessageBox.Show(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">faile</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            }<br />            NetMAPI.Term();<br />            </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.dataGrid1.DataSource </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mydt;<br />        }<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">读取发件箱内短信</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> button2_Click(</span><span style="color: rgb(0, 0, 255);">object</span><span style="color: rgb(0, 0, 0);"> sender, EventArgs e)<br />        {<br />            DataTable mydt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataTable();<br />            mydt.TableName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendedBox</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderAddress</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Subject</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(DateTime)));<br />            mydt.Columns.Add(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DataColumn(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">typeof</span><span style="color: rgb(0, 0, 0);">(DateTime)));<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (NetMAPI.MAPIInit())<br />            {<br /><br />                NetMAPI mapi </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> NetMAPI();<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.Login())<br />                {<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.OpenMessageStore())<br />                    {<br /><br />                        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.OpenSentItems())<br />                        {<br /><br />                            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mapi.GetContents())<br />                            {<br /><br />                                SmsMessage msg;<br />                                StringBuilder s </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringBuilder(</span><span style="color: rgb(0, 0, 0);">140</span><span style="color: rgb(0, 0, 0);">);<br />                                StringBuilder s1 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringBuilder(</span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);">);<br />                                StringBuilder s2 </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringBuilder(</span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);">);<br />                                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                                DataRow dr;<br />                                </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (mapi.GetNextMessage(</span><span style="color: rgb(0, 0, 255);">out</span><span style="color: rgb(0, 0, 0);"> msg, </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">))<br />                                {<br />                                    i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">;<br /><br />                                    dr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mydt.NewRow();<br />                                    msg.GetRecipients();<br />                                    SmsMessage.RecipientType tt;<br />                                    msg.GetNextRecipient(s1, s2, </span><span style="color: rgb(0, 0, 255);">out</span><span style="color: rgb(0, 0, 0);"> tt);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s1.ToString();<br />      <br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SenderAddress</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s2.ToString();<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">MessageBox.Show(aa);<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">MessageBox.Show(s.ToString());</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                                    msg.GetSubject(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Subject</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    </span><span style="color: rgb(0, 128, 0);">/**/</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">/MessageBox.Show(s.ToString());</span><span style="color: rgb(128, 128, 128);"><br /></span><span style="color: rgb(0, 0, 0);">                                    msg.GetSubmitTime(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SendTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    msg.GetReceivedTime(s);<br />                                    dr[</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ReceiveTime</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> s.ToString();<br />                                    msg.Dispose();<br />                                    mydt.Rows.Add(dr);<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">if (i &gt; 230)<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">{<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">    break;<br />                                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">}</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />                                }<br /><br />                            }<br />                        }<br /><br />                    }<br /><br />                    mapi.Logout();<br />                }<br />            }<br />            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />            {<br />                MessageBox.Show(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">faile</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            }<br />            NetMAPI.Term();<br />            </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.dataGrid1.DataSource </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mydt;<br /><br />        }<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">这两段代码读取的是收件箱和发件箱里全部短信,还不是很理想<img src="http://www.cppblog.com/images/dot.gif" />.. </span></div><br /><br /><br /><br /><img src ="http://www.cppblog.com/msopengl/aggbug/150313.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/msopengl/" target="_blank">jemmyLiu</a> 2011-07-06 17:14 <a href="http://www.cppblog.com/msopengl/archive/2011/07/06/150313.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WinCE开发上网记录读取问题</title><link>http://www.cppblog.com/msopengl/archive/2011/06/10/148449.html</link><dc:creator>jemmyLiu</dc:creator><author>jemmyLiu</author><pubDate>Fri, 10 Jun 2011 10:31:00 GMT</pubDate><guid>http://www.cppblog.com/msopengl/archive/2011/06/10/148449.html</guid><wfw:comment>http://www.cppblog.com/msopengl/comments/148449.html</wfw:comment><comments>http://www.cppblog.com/msopengl/archive/2011/06/10/148449.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/msopengl/comments/commentRss/148449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/msopengl/services/trackbacks/148449.html</trackback:ping><description><![CDATA[
		<font size="2">   最近在做Window Mobile 6 的开发过程中，对于读取IE浏览器历史记录过程<br />    发现问题如下：<br />  1.尝试使用CreateFile进行Open操作发现返回句柄无效，目标操作文件问\Content.IE5\index.dat<br />     此文件一直被浏览器占用，但打开手机浏览器查看进程管理器并无浏览器进程打开<br />  2.第二种方式采用CeCopyFile同样的结果Copy失败<br />  3.方式三Window mobile 6 SDK从头到尾只有一个操作Browser Cache的借口，函数名FindFirstUrlCacheEntry<br />    但发现此函数应该为C#函数，Windows mobile 6 Win32不能使用<br /><br /><br />   MSDN论坛发现很多同样的问题，但均无一个合理的解答，多数都是未提供API<br />   我就郁闷了，难道我就得不到Windows Mobile的上网记录信息了么？<br />   希望高手帮忙解答，真的很急，所以被迫发在跪谢！</font>
<img src ="http://www.cppblog.com/msopengl/aggbug/148449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/msopengl/" target="_blank">jemmyLiu</a> 2011-06-10 18:31 <a href="http://www.cppblog.com/msopengl/archive/2011/06/10/148449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HASH校验（MD5 SHA256）</title><link>http://www.cppblog.com/msopengl/archive/2011/02/28/140769.html</link><dc:creator>jemmyLiu</dc:creator><author>jemmyLiu</author><pubDate>Mon, 28 Feb 2011 01:42:00 GMT</pubDate><guid>http://www.cppblog.com/msopengl/archive/2011/02/28/140769.html</guid><wfw:comment>http://www.cppblog.com/msopengl/comments/140769.html</wfw:comment><comments>http://www.cppblog.com/msopengl/archive/2011/02/28/140769.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/msopengl/comments/commentRss/140769.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/msopengl/services/trackbacks/140769.html</trackback:ping><description><![CDATA[
		<div id="cnblogs_post_body">
				<p align="center">
						<strong>OpenSSL </strong>
						<strong>使用指南 </strong>
				</p>
				<p align="center">
						<font face="Verdana">http://www.fs2you.com/files/5b43b3b0-5e3d-11dd-9b38-0019d11a795f/</font>  </p>
				<p>  </p>
				<p>
						<strong>目录 </strong>
				</p>
				<p>•  介绍 </p>
				<p>•  编译 </p>
				<p>•  运行 OpenSSL.exe </p>
				<p>•  算法编程 API </p>
				<p>4.1 对称算法 </p>
				<p>4.1.1 DES </p>
				<p>4.1.2 A ES </p>
				<p>4.1.3 RC4 </p>
				<p>4.1.4 EVP_ </p>
				<p>4.2 公钥算法 </p>
				<p>4.3 Hash 算法 </p>
				<p>4.4 随机数算法 </p>
				<p>•  SSL 协议编程 API </p>
				<p>•  CA 和证书 </p>
				<p>•    </p>
				<p>•  参考网址 </p>
				<p>•    </p>
				<p>•  示例程序 </p>
				<p>•    </p>
				<br />
				<p>  </p>
				<p>•  <strong>介绍 </strong></p>
				<p>OpenSSL 是使用非常广泛的 SSL 的开源实现。由于其中实现了为 SSL 所用的各种加密算法，因此 OpenSSL 也是被广泛使用的加密函数库。 </p>
				<p>
						<strong>1.1 SSL </strong>
				</p>
				<p>SSL(Secure Socket Layer) 安全协议是由 Netscape 公司首先提出，最初用在保护 Navigator 浏览器和
 Web 服务器之间的 HTTP 通信 ( 即 HTTPS) 。后来 SSL 协议成为传输层安全通信事实上的标准，并被 IETF 吸收改进为 
TLS(Transport Layer Security) 协议。 </p>
				<p>SSL/TLS 协议位于 TCP 协议和应用层协议之间，为传输双方提供认证、加密和完整性保护等安全服务。 SSL 作为一个协议框架，通信双方可以选用合适的对称算法、公钥算法、 MAC 算法等密码算法实现安全服务。 </p>
				<p>
						<strong>1.2 OpenSSL </strong>
				</p>
				<p>OpenSSL 是著名的 SSL 的开源实现，是用 C 语言实现的。 </p>
				<p>OpenSSL 的前身是 SSLeay ，一个由 Eric Young 开发的 SSL 的开源实现，支持 SSLv2/v3 和 TLSv1 。 </p>
				<p>伴随着 SSL 协议的普及应用， OpenSSL 被广泛应用在基于 TCP/Socket 的网络程序中，尤其是 OpenSSL 和 Apache 相结合，是很多电子商务网站服务器的典型配置。 </p>
				<p>  </p>
				<p>•  <strong>编译和安装 OpenSSL </strong></p>
				<p>OpenSSL 开放源代码，这对学习、分析 SSL 和各种密码算法提供了机会，也便于在上面进一步开发。 </p>
				<p>
						<strong>2.1 </strong>
						<strong>获得 OpenSSL </strong>
				</p>
				<p>到 OpenSSL 的网站即可下载当前版本的 OpenSSL 源代码压缩包。 </p>
				<p>当前版本 openssl- 0.9.8 .tar.gz ，只有 3M 多，比较精简。解压缩后得到一个目录 openssl-0.9.8 
，共有约 1800 个文件， 15M 。其中 crypto 子目录中是众多密码算法实现， ssl 子目录中是 SSL 协议的实现。 </p>
				<p>在 Linux 中解压缩： </p>
				<p>$tar zxf openssl- 0.9.8 .tar.gz </p>
				<p>在 Windows 中可以使用 winzip 或 winrar 。 </p>
				<p>
						<strong>2.2 </strong>
						<strong>编译工具 </strong>
				</p>
				<p>编译 OpenSSL 需要 Perl 和 C 编译器。在 Windows 下如果要用加密算法的汇编代码实现，还需要 masm 或 nasm 汇编器。 ( 汇编代码可以比 C 代码显著提高密码运算速度 ) </p>
				<p>Perl 在 Windows 下推荐使用 Active Perl 。 </p>
				<p>C 编译器可以使用 gcc 。在 W indows 下可以使用 Visual C 编译器。 </p>
				<p>汇编器推荐使用 nasm 。 </p>
				<p>这些工具所在目录必须加入到 PATH 环境变量中去。 </p>
				<p>
						<strong>2.3 </strong>
						<strong>编译和安装步骤 </strong>
				</p>
				<p>查看 readme 是个好习惯。从 readme 了解到需要进一步查看 INSTALL 和 INSTALL.W32 文件。 </p>
				<p>在 Windows 中： </p>
				<p>&gt;perl Configure VC-WIN32 </p>
				<p>&gt;ms\do_nasm ( 如果不使用汇编代码实现，则可 &gt;ms\do_ms) </p>
				<p>&gt;nmake -f ms\ntdll.mak </p>
				<p>&gt;cd out32dll </p>
				<p>&gt;..\ms\test </p>
				<p>编译结果得到头文件、链接库、运行库和 openssl.exe 工具。头文件位于 ./inc32 或者 ./inculde 目录，有一个 
openssl 子目录，内有几十个 .h 文件。链接库即 ./out32dll 目录中的 libeay32.lib 和 ssleay32.lib
 ，分别是密码算法相关的和 ssl 协议相关的。运行库是 ./out32dll 目录中的 libeay32.dll 和 ssleay32.dll
 ，和链接库相对应。在 ./out32dll 中还有一个工具 openssl.exe ，可以直接用来测试性能、产生 RSA 
密钥、加解密文件，甚至可以用来维护一个测试用的 CA 。 </p>
				<p>在 Linux 中的编译和安装步骤较简单 ： </p>
				<p>$./config </p>
				<p>$make </p>
				<p>$make test </p>
				<p>$make install </p>
				<p>在 Linux 下，头文件、库文件、工具都已被安装放到了合适的位置。库文件是 .a 或 .so 格式。 </p>
				<p>  </p>
				<p>•  <strong>使用 OpenSSL.exe </strong><strong></strong></p>
				<p>使用 OpenSSL.exe(Linux 中可执行文件名是 openssl) 可以做很多工作，是一个很好的测试或调试工具。 </p>
				<p>
						<strong>3.1 </strong>
						<strong>版本和编译参数 </strong>
				</p>
				<p>显示版本和编译参数： &gt;openssl version -a </p>
				<p>
						<strong>3.2 </strong>
						<strong>支持的子命令、密码算法 </strong>
				</p>
				<p>查看支持的子命令： &gt;openssl ? </p>
				<p>SSL 密码组合列表： &gt;openssl ciphers </p>
				<p>
						<strong>3.3 </strong>
						<strong>测试密码算法速度 </strong>
				</p>
				<p>测试所有算法速度： &gt;openssl speed </p>
				<p>测试 RSA 速度： &gt;openssl speed rsa </p>
				<p>测试 DES 速度： &gt;openssl speed des </p>
				<p>
						<strong>3.4 RSA </strong>
						<strong>密钥操作 </strong>
				</p>
				<p>产生 RSA 密钥对： &gt;openssl genrsa -out 1.key 1024 </p>
				<p>取出 RSA 公钥： &gt;openssl rsa -in 1.key -pubout -out 1.pubkey </p>
				<p>
						<strong>3.5 </strong>
						<strong>加密文件 </strong>
				</p>
				<p>加密文件： &gt;openssl enc -e -rc4 -in 1.key -out 1.key.enc </p>
				<p>解密文件： &gt;openssl enc -d -rc4 -in 1.key.enc -out 1.key.dec </p>
				<p>
						<strong>3.6 </strong>
						<strong>计算 Hash 值 </strong>
				</p>
				<p>计算文件的 MD5 值： &gt;openssl md5 &lt; 1.key </p>
				<p>计算文件的 SHA1 值： &gt;openssl sha1 &lt; 1.key </p>
				<p>  </p>
				<p>•  <strong>算法编程 API </strong></p>
				<p>OpenSSL 中支持众多的密码算法，并提供了很好的封装和接口。密码算法主要分为如下几类：对称算法、公钥算法、散列算法、随机数产生算法等。 </p>
				<p>OpenSSL 的目标是实现安全协议。其中相关协议和标准包括： SSL/TLS 、 PKCS#1 、 PCKS#10 、 X.509 、 PEM 、 OCSP 等。 </p>
				<p>
						<strong>4.1 </strong>
						<strong>对称算法接口 </strong>
				</p>
				<p>OpenSSL 中实现的对称算法太多，举三个例子： DES 、 AES 、 RC4 。 </p>
				<p>
						<strong>4.1.1 </strong>
						<strong>DES </strong>
				</p>
				<p>DES 加密算法是分组算法。 DES 的基本操作是把 64 比特明文在 56 比特密钥指引下加密成 64 比特密文。在实际使用中把密钥看作 64 比特可以更方便。 </p>
				<p>DES （ IN ， KEY ） = OUT </p>
				<p>
						<strong>(1) DES ECB </strong>
						<strong>模式 </strong>
				</p>
				<p>在 OpenSSL 中 ECB 操作模式对应的函数是 DES_ecb_encrypt() ，该函数把一个 8 字节明文分组 input 
加密成为一个 8 字节密文分组 output 。参数中密钥结构 ks 是用函数 DES_set_key() 准备好的，而密钥 key 
是用随机数算法产生的 64 个随机比特。参数 enc 指示是加密还是解密。该函数每次只加密一个分组，因此用来加密很多数据时不方便使用。 </p>
				<p>void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, DES_key_schedule *ks,int enc); </p>
				<p>int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); </p>
				<p>
						<strong>(2) DES CBC </strong>
						<strong>模式 </strong>
				</p>
				<p>DES 算法 CBC 操作模式加解密函数是 DES_ncbc_encrypt() 。参数 length 指示输入字节长度。如果长度不是 8 字节的倍数，则会被用 0 填充到 8 字节倍数。因此，输出可能比 length 长，而且必然是 8 字节的倍数。 </p>
				<p>void DES_ncbc_encrypt(const unsigned char *input,unsigned char 
*output, long length, DES_key_schedule *schedule, DES_cblock *ivec, int 
enc); </p>
				<p>
						<strong>(3) DES CFB </strong>
						<strong>模式 </strong>
				</p>
				<p>DES 算法 CFB 操作模式加解密函数是 DES_cfb_encrypt() 。参数 length 指示输入字节长度。参数 
numbits 则指示了 CFB 每次循环加密多少明文比特，也即密文反馈的比特数目。 ivec 是初始向量，被看做第 0 
个密文分组，是不用保密但应随机取值的 8 个字节。如果在一次会话中数次调用 DES_cfb_encrypt() ，则应该记忆 ivec 。由于 
CFB 模式中每次 DES 基本操作只加密 numbits 比特明文，因此如果 numbits 太小则效率太低。 </p>
				<p>void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int
 numbits, long length, DES_key_schedule *schedule, DES_cblock *ivec, int
 enc); </p>
				<p>另有一个 numbit 是 64 比特的版本，既高效又没有填充的麻烦，推荐使用。 num 中的返回值指示了 ivec 中的状态，是和下次调用衔接的。 </p>
				<p>void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, 
long length, DES_key_schedule *schedule, DES_cblock *ivec, int *num, int
 enc) ； </p>
				<p>
						<strong>(4) DES OFB </strong>
						<strong>模式 </strong>
				</p>
				<p>OFB 和 CFB 类似，也有两个函数，用法一样。 </p>
				<p>void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int 
numbits,long length,DES_key_schedule *schedule,DES_cblock *ivec); </p>
				<p>void DES_ofb64_encrypt(const unsigned char *in,unsigned char 
*out,long length,DES_key_schedule *schedule,DES_cblock *ivec,int *num); </p>
				<p>
						<strong>(5) DES </strong>
						<strong>函数示例程序 </strong>
				</p>
				<p>见附件 A.1 。 </p>
				<p>
						<strong>4.1.2 A </strong>
						<strong>ES </strong>
				</p>
				<p>AES 加密算法是分组算法。典型参数的 AES 的基本操作是把 128 比特明文在 128 比特密钥指引下加密成 128 比特密文。 </p>
				<p>AES （ IN ， KEY ） = OUT </p>
				<p>OpenSSL 中关于 AES 的函数名和参数接口和 DES 的雷同。相关函数名如下 ( 参数略 ) 。 </p>
				<p>int AES_set_encrypt_key(); </p>
				<p>int AES_set_decrypt_key(); </p>
				<p>void AES_ecb_encrypt(); </p>
				<p>void AES_cbc_encrypt(); </p>
				<p>void AES_cfb128_encrypt(); </p>
				<p>void AES_ofb128_encrypt(); </p>
				<p>AES 示例程序见附件 A.2 。 </p>
				<p>
						<strong>4.1.3 </strong>
						<strong>RC4 </strong>
				</p>
				<p>RC4 密码算法是流算法，也叫序列算法。流算法是从密钥作为种子产生密钥流，明文比特流和密钥流异或即加密。 RC4 算法由于算法简洁，速度极快，密钥长度可变，而且也没有填充的麻烦，因此在很多场合值得大力推荐。 </p>
				<p>OpenSSL 中 RC4 算法有两个函数 : RC4_set_key() 设置密钥， RC4() 加解密。可以把 RC4 看作异或，因此加密两次即解密。 </p>
				<p>void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); </p>
				<p>void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, unsigned char *outdata); </p>
				<p>RC4 示例程序见附件 A.3 。 </p>
				<p>例子 A.3.(1) 是利用 OpenSSL 动态库函数。例子 A.3.(2) 是把 RC4 的实现代码从 OpenSSL 中分离出来的。例子 A.3.(3) 是另一个演示实现。 </p>
				<p>
						<strong>4.2 </strong>
						<strong>公钥算法 </strong>
						<strong>
						</strong>
				</p>
				<p>OpenSSL 中实现了 RSA 、 DSA 、 ECDSA 等公钥算法。 </p>
				<p>
						<strong>4.2.1 </strong>
						<strong>RSA </strong>
				</p>
				<p>RSA 是分组算法，典型的密钥模长度 1024 比特时，分组即是 1024 比特，即 128 字节。 </p>
				<p>
						<strong>(1) RSA </strong>
						<strong>密钥 </strong>
				</p>
				<p>RSA 密钥产生函数 RSA_generate_key() ，需要指定模长比特数 bits 和公钥指数 e 。另外两个参数为 NULL 即可。 </p>
				<p>RSA * RSA_generate_key(int bits, unsigned long e, void (*callback) (int,int,void *),void *cb_arg); </p>
				<p>如果从文件中读取密钥，可使用函数 PEM_read_bio_PrivateKey()/ PEM_read_bio_PUBKEY(); EVP_PKEY 中包含一个 RSA 结构，可以引用。 </p>
				<p>EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); </p>
				<p>
						<strong>(2) RSA </strong>
						<strong>加密解密 </strong>
				</p>
				<p>RSA 加密函数 RSA_public_encrypt() 使用公钥部分，解密函数 RSA_private_decrypt() 
使用私钥。填充方式常用的有两种 RSA_PKCS1_PADDING 和 RSA_PKCS1_OAEP_PADDING 。出错时返回 -1 
。输入必须比 RSA 钥模长短至少 11 个字节（在 RSA_PKCS1_PADDING 时？）。输出长度等于 RSA 钥的模长。 </p>
				<p>int RSA_public_encrypt(int flen, const unsigned char *from,unsigned char *to, RSA *rsa,int padding); </p>
				<p>int RSA_private_decrypt(int flen, const unsigned char *from,unsigned char *to, RSA *rsa,int padding); </p>
				<p>
						<strong>(3) </strong>
						<strong>签名和验证 </strong>
				</p>
				<p>签名使用私钥，验证使用公钥。 RSA 签名是把被签署消息的散列值编码后用私钥加密，因此函数中参数 type 用来指示散列函数的类型，一般是 NID_md5 或 NID_sha1 。正确情况下返回 0 。 </p>
				<p>int RSA_sign(int type, const unsigned char *m, unsigned int m_length, unsigned char *sigret, unsigned int *siglen, RSA *rsa); </p>
				<p>int RSA_verify(int type, const unsigned char *m, unsigned int m_length, unsigned char *sigbuf, unsigned int siglen, RSA *rsa); </p>
				<p>
						<strong>(4) RSA </strong>
						<strong>函数示例程序 </strong>
				</p>
				<p>RSA 示例程序见附件 A.4 。 </p>
				<p>例子 A.4.(1) 是加密解密例子。例子 A.4.(2) 是签名验证例子。 </p>
				<p>
						<strong>4.2.2 </strong>
						<strong>DSA </strong>
				</p>
				<p>
						<strong>
						</strong>
						<strong>（ TOBE ） </strong>
				</p>
				<p>
						<strong>4.2.2 </strong>
						<strong>ECDSA </strong>
				</p>
				<p>
						<strong>（ or NOT TOBE ） </strong>
				</p>
				<p>
						<strong>4.3 Hash </strong>
						<strong>算法 </strong>
				</p>
				<p>Hash 算法举 MD5 和 SHA1 两个例子。 Hash 算法重复接收用户输入，直到最后一次结束时输出散列结果。 </p>
				<p>
						<strong>4.3.1 </strong>
						<strong>MD5 </strong>
				</p>
				<p>MD5 算法输出的散列值是 16 字节。 </p>
				<p>int MD5_Init(MD5_CTX *c); </p>
				<p>int MD5_Update(MD5_CTX *c, const void *data, size_t len); </p>
				<p>int MD5_Final(unsigned char *md, MD5_CTX *c); </p>
				<p>
						<strong>4.3.2 </strong>
						<strong>SHA1 </strong>
				</p>
				<p>SHA1 算法输出的散列值是 20 字节。 </p>
				<p>int SHA1_Init(SHA_CTX *c); </p>
				<p>int SHA1_Update(SHA_CTX *c, const void *data, size_t len); </p>
				<p>int SHA1_Final(unsigned char *md, SHA_CTX *c); </p>
				<p>
						<strong>4.3.3 </strong>
						<strong>MD5 </strong>
						<strong>例子 </strong>
				</p>
				<p>MD5 示例程序见附件 A.5 。 </p>
				<p>md5sum 这是一个实用小工具，可以计算一个文件的 MD5 值。 </p>
				<p>
						<strong>4.4 </strong>
						<strong>随机数算法 </strong>
				</p>
				<p>随机性是密码安全的基石。为了产生安全的伪随机数，必须有好的随机因素作为种子。 OpenSSL 在内部做了努力，但是仍建议在实用随机数产生函数之前添加随机因素。 </p>
				<p>函数 RAND_add() 可以添加随机因素到内部状态中去。然后，即可以使用 RAND_bytes() 获得随机数。 </p>
				<p>void RAND_add(const void *buf,int num,double entropy); </p>
				<p>int RAND_bytes(unsigned char *buf,int num); </p>
				<p>  </p>
				<p>•  <strong>SSL </strong><strong>协议编程 API </strong></p>
				<p>
						<strong>5.1 </strong>
						<strong>客户端 </strong>
				</p>
				<p>
						<strong>5.2 </strong>
						<strong>服务器端 </strong>
				</p>
				<p>
						<strong>5.3 SSL </strong>
						<strong>示例程序 </strong>
				</p>
				<p>参见 A.6 。 </p>
				<p>
						<strong>  </strong>
				</p>
				<p>•  <strong>CA </strong><strong>和证书 </strong></p>
				<p>
						<strong>6.1 OpenSSL </strong>
						<strong>中 CA 的配置 </strong>
				</p>
				<p>
						<strong>6.2 </strong>
						<strong>配置示例 </strong>
				</p>
				<p>参见 A.7.(1) 。 </p>
				<p>
						<strong>6.3 </strong>
						<strong>证书解析 </strong>
				</p>
				<p>
						<strong>6.4 </strong>
						<strong>解析示例程序 </strong>
				</p>
				<p>参见 A.7.(2) 。 </p>
				<p>  </p>
				<p>•  <strong>  </strong></p>
				<p>  </p>
				<p>•  <strong>参考网址 </strong><strong></strong></p>
				<p>SSL 3.0 Specification </p>
				<p>
						<a href="http://www.netscape.com/eng/ssl3/">http://www.netscape.com/eng/ssl3/</a>
				</p>
				<p>Transp ort Layer Security (tls) Charter </p>
				<p>
						<a href="http://www.ietf.org/html.charters/tls-charter.html">http://www.ietf.org/html.charters/tls-charter.html</a>
				</p>
				<p>OpenSSL: The Open Source toolkit for SSL/TLS </p>
				<p>
						<a href="http://www.openssl.org/">http://www.openssl.org/</a>
				</p>
				<p>SSLeay </p>
				<p>
						<a href="http://www2.psy.uq.edu.au/%7Eftp/Crypto/">http://www2.psy.uq.edu.au/~ftp/Crypto/</a>
				</p>
				<p>OpenSSL 中文论坛 </p>
				<p>
						<a href="http://openssl.cn/">http://openssl.cn/</a>
				</p>
				<p>Perl </p>
				<p>
						<a href="http://www.cpan.org/src/README.html">http://www.cpan.org/src/README.html</a>
				</p>
				<p>
						<a href="http://www.activestate.com/Products/ActivePerl/">http://www.activestate.com/Products/ActivePerl/</a>
				</p>
				<p>NASM </p>
				<p>
						<a href="http://www.perl.com/">http://www.perl.com/</a>
				</p>
				<p>
						<a href="http://www.moruite.com/index.asp">studio</a>
				</p>
				<p>
						<strong>  </strong>
				</p>
				<p>•  <strong>  </strong></p>
				<p>  </p>
				<p>•  <strong>示例程序 </strong></p>
				<p>注 : 此嵌入的文件对象可以被拖放到磁盘目录中去。 </p>
				<br />
				<p>•  DES 示例程序 </p>
				<p>•  AES 示例程序 </p>
				<br />
				<p>•  RC4 示例程序 </p>
				<p>（ 1 ）． （ 2 ）． （ 3 ） </p>
				<p>•  RSA 示例程序 </p>
				<p>（ 1 ）． （ 2 ）． </p>
				<p>•  Hash 算法示例程序 </p>
				<p>•  SSL 示例程序 </p>
				<p>•  CA 配置示例和证书解析示例程序 </p>
				<p>(1). (2). </p>
				<p>•    </p>
				<p>•    <br /></p>
				<p>引自：http://www.cnblogs.com/ahuo/archive/2008/07/30/1256820.html<br /></p>
		</div>
<img src ="http://www.cppblog.com/msopengl/aggbug/140769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/msopengl/" target="_blank">jemmyLiu</a> 2011-02-28 09:42 <a href="http://www.cppblog.com/msopengl/archive/2011/02/28/140769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>