<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-292733216495360733</id><updated>2011-04-22T13:39:48.783+08:00</updated><category term='Newegg'/><category term='Title'/><category term='Dcg'/><category term='Ingrian'/><category term='jQuery'/><category term='F#'/><category term='TR'/><category term='JavaScript'/><category term='Google'/><category term='GreaseMonkey'/><category term='Code Styler'/><category term='TechED'/><title type='text'>代码 |&gt; 创造世界 |&gt; (属于 我)</title><subtitle type='html'>用代码创建一个属于我的世界……</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-8392086232654895140</id><published>2009-01-02T19:47:00.003+08:00</published><updated>2009-01-16T08:53:17.452+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code Styler'/><title type='text'>CodeStyler v0.2 Release</title><content type='html'>&lt;p&gt;变动如下：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;新增了内置的Python语法支持&lt;/li&gt;
&lt;li&gt;Fix了样式模板的一些跨浏览器兼容问题&lt;/li&gt;
&lt;li&gt;补充了一些C#特殊操作符的支持&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Enjoy! :)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://code.google.com/p/code-styler/" target="_blank"&gt;http://code.google.com/p/code-styler/&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-8392086232654895140?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/8392086232654895140/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2009/01/codestyle-v02-release.html#comment-form' title='2 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/8392086232654895140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/8392086232654895140'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2009/01/codestyle-v02-release.html' title='CodeStyler v0.2 Release'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-9025662448796656309</id><published>2009-01-01T14:20:00.003+08:00</published><updated>2009-01-01T14:42:24.816+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code Styler'/><title type='text'>CodeStyler for your Blog</title><content type='html'>&lt;p&gt;首先，在这2009年的第一个日子里，祝大家元旦快乐，在新的一年中心想事成。在这个特殊的日子里作为程序员的我也要特殊地庆祝一番。今天这个时刻我向全世界发布CodeStyler，我做的一个给代码上色的小工具，献给每一位程序员博客。:)&lt;/p&gt;

&lt;p&gt;
项目首页

&lt;a href="http://code.google.com/p/code-styler/" target="_blank"&gt;http://code.google.com/p/code-styler/&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
下载

&lt;a href="http://code.google.com/p/code-styler/downloads/list" target="_blank"&gt;http://code.google.com/p/code-styler/downloads/list&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;首先来说说为什么我要"Reinvent the wheel"，也就是说说CodeStyler与众不同之处。其实与众不同之处也没那么多，我个人认为就一个“方便”，主要体现在两点：&lt;span style="background-color: rgb(255, 255, 180);"&gt;不依赖于任何博客，随时随地可以格式化代码；不需要修改代码就可以增加对新语言的支持。&lt;/span&gt;其中我对第二点的需求是很重视的，因为这意味着高可扩展性，尤其是当我增加了对Dcg模板语法的支持后更加欣赏这个功能了。:)&lt;/p&gt;

&lt;p&gt;想新增一个语法的支持很容易，不需要改代码，只要提供两个文件就可以了：一个语法的规则文件，一个样式模板文件。语法规则文件是由一系列正则表达式组成的，描述了语法的各个组成部分（想上色的部分）正则表达式之间有顺序关系，先匹配第一行，替换，再匹配下一行，以此类推。样式模板文件就是一个Dcg语法的模板，它接受一个IEnumerable&amp;lt;Token&amp;gt;参数，这个参数在遍历时会返回一个一个的token（识别出的语法组成部分和普通的文本），接下来想怎么格式化便随意了。在下载的zip包中有源代码，LGPL License，里面有一些自带的语法支持，如C#、HTML、Dcg等可以拿来做参考。:)&lt;/p&gt;

&lt;p&gt;此次代码编写的感受就是正则表达式真XX难调，费了九牛二虎之力终于可以面向大家公开了。我个人将自己的一些代码都试了一遍，保证没有问题，不过由于是第一版，加上正则表达式实在容易出错，所以各位实际用下来如果碰到什么问题还请在项目网站上反馈一下，我会尽快fix。下面是一张CodeStyler的窗口截图和一段用CodeStyler格式出来的代码，演示用。&lt;/p&gt;

&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_TtUDCDHbyoo/SVxgMbQIxkI/AAAAAAAABMA/M0i-XeEvFtI/s1600-h/CodeStyler-Preview.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 262px;" src="http://4.bp.blogspot.com/_TtUDCDHbyoo/SVxgMbQIxkI/AAAAAAAABMA/M0i-XeEvFtI/s320/CodeStyler-Preview.gif" alt="" id="BLOGGER_PHOTO_ID_5286205829216257602" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div   style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; max-height: 250px; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;
 &lt;div  style="border-style: none; padding: 0px; overflow: visible; width: 100%; line-height: 12pt;color:black;"&gt;
&lt;pre  style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; line-height: 12pt;color:black;"&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Welcome&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;style&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"text/css"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;       &lt;span style="color: rgb(163, 21, 21);"&gt;body p &lt;/span&gt;{ &lt;span style="color: rgb(255, 0, 0);"&gt;color&lt;/span&gt;:&lt;span style="color: rgb(0, 0, 255);"&gt; black &lt;/span&gt;}
&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;       &lt;span style="color: rgb(163, 21, 21);"&gt;#myid &lt;/span&gt;{
&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         &lt;span style="color: rgb(255, 0, 0);"&gt;margin&lt;/span&gt;:&lt;span style="color: rgb(0, 0, 255);"&gt; 10px&lt;/span&gt;;
&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;       }
&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;style&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;script&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; foo(a, b) {
&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; c &lt;span style="color: rgb(255, 0, 255);"&gt;=&lt;/span&gt; 1;
&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; a &lt;span style="color: rgb(255, 0, 255);"&gt;+&lt;/span&gt; b &lt;span style="color: rgb(255, 0, 255);"&gt;+&lt;/span&gt; c;
&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;       }
&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;script&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;p&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;Hello World&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;p&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
 &lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-9025662448796656309?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/9025662448796656309/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2009/01/codestyler-for-your-blog.html#comment-form' title='3 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/9025662448796656309'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/9025662448796656309'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2009/01/codestyler-for-your-blog.html' title='CodeStyler for your Blog'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_TtUDCDHbyoo/SVxgMbQIxkI/AAAAAAAABMA/M0i-XeEvFtI/s72-c/CodeStyler-Preview.gif' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-8436938926272415742</id><published>2008-12-29T19:39:00.004+08:00</published><updated>2008-12-29T19:51:09.314+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dcg'/><title type='text'>DCG v3.3.100 Released</title><content type='html'>&lt;p&gt;v3.3.100是一个bug fix release，即，没有功能的添加而是修复了一些bug。修复的bug如下：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;在有缩进的block中控制行结束与否的"@"不能正确工作，虽然不会输出新行，但是会追加block的缩进，这是一个错误的行为。&lt;/li&gt;
  &lt;li&gt;模板输出中的换行符在Windows下永远都是"\r\n"，在Linux下永远都是"\n"，这是不正确的。正确的做法是根据模板文件的换行符来决定输出的换行符。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;建议所有使用v3.3.90的人都更新到v3.3.100。&lt;/p&gt;

&lt;p&gt;&lt;a href="http://code.google.com/p/dcg/downloads/list" target="_blank"&gt;http://code.google.com/p/dcg/downloads/list&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-8436938926272415742?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/8436938926272415742/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/12/dcg-v33100-released.html#comment-form' title='4 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/8436938926272415742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/8436938926272415742'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/12/dcg-v33100-released.html' title='DCG v3.3.100 Released'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-3557328105718107292</id><published>2008-12-25T21:06:00.005+08:00</published><updated>2008-12-26T08:52:56.251+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dcg'/><title type='text'>DCG v3.3.90 Released</title><content type='html'>&lt;p&gt;在计划了三个月后，DCG v3.3.90终于被我完成并发布了，今天正好是12月25号，作为圣诞礼物送给大家吧。&lt;/p&gt;

&lt;p&gt;改动如下：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;内部Parsing的方式进行了重构，终于采用了AST。这样模板语法的扩展能力就更强了，否则不好扩展。&lt;/li&gt;
  &lt;li&gt;终于实现了一个我称之为Private Section的功能，可以将其想象成模板中的模板，支持Recursive调用。&lt;/li&gt;
  &lt;li&gt;支持.NET Framework 3.5和C# 3.0了，受其影响，构造函数多了几个Overload。&lt;/li&gt;
  &lt;li&gt;Bug fixes，一些不怎么鲜为人知的bug被fix掉了。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;秀一个Recursive Private Section调用的代码片段：&lt;/p&gt;

&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_TtUDCDHbyoo/SVOJF6MBOfI/AAAAAAAABL4/g6at664Gg-I/s1600-h/recursive_private_section.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; cursor: pointer; width: 225px; height: 200px;" src="http://2.bp.blogspot.com/_TtUDCDHbyoo/SVOJF6MBOfI/AAAAAAAABL4/g6at664Gg-I/s320/recursive_private_section.gif" alt="" id="BLOGGER_PHOTO_ID_5283717522447743474" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;介于DCG的用户也有一定规模了（两个团队，Orz），我争取在接下来的一段日子里从头到尾在Blog中仔细描述DCG的各种使用方法、它的语法等，并同时会给出相关内容的示例模板，敬请期待。:)&lt;/p&gt;

&lt;p&gt;这里有两个关于DCG的连接：&lt;/p&gt;

&lt;p&gt;Dcg项目首页及下载：&lt;a href="http://code.google.com/p/dcg/" target="_blank"&gt;http://code.google.com/p/dcg/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dcg讨论组，可用来沟通：&lt;a href="http://groups.google.com/group/dynamic-code-generator" target="_blank"&gt;http://groups.google.com/group/dynamic-code-generator&lt;/a&gt;，这个在项目首页也有链接。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-3557328105718107292?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/3557328105718107292/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/12/dcg-v3390-released.html#comment-form' title='4 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/3557328105718107292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/3557328105718107292'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/12/dcg-v3390-released.html' title='DCG v3.3.90 Released'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_TtUDCDHbyoo/SVOJF6MBOfI/AAAAAAAABL4/g6at664Gg-I/s72-c/recursive_private_section.gif' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-7118105271204706071</id><published>2008-12-17T21:04:00.001+08:00</published><updated>2008-12-17T21:11:12.358+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='GreaseMonkey'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google帐号自动登录脚本</title><content type='html'>&lt;p&gt;近日发现自己用的Google服务是越来越多了。有些服务例如Google SearchWiki需要先登录才能够使用，日常使用又嫌登录比较麻烦，所以听从了同事的意见做了一个GreaseMonkey脚本，可以在访问任一Google页面时登录，如果还没有登录过的话。&lt;/p&gt;

&lt;p&gt;我写了两个脚本来满足这个需求，两个脚本要合起来用。一个是负责将页面转到登录页面的，另一个是负责自动填充表单并提交的。脚本已上传到了&lt;a href="http://userscripts.org/" target="_blank"&gt;userscripts.org&lt;/a&gt;上了，链接如下：&lt;/p&gt;

&lt;p&gt;&lt;a href="http://userscripts.org/scripts/show/38810" target="_blank"&gt;Google Redirect to Login&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://userscripts.org/scripts/show/38809" target="_blank"&gt;Google Auto Login&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;安装好后需要改一下帐号信息，将&lt;strong&gt;YOUR_ACCOUNT_NAME&lt;/strong&gt;改为你自己的Google帐号名，将&lt;strong&gt;YOUR_PASSWORD&lt;/strong&gt;改为你自己的Google帐号密码。&lt;/p&gt;

&lt;p&gt;这套脚本的优势就在于无论你有没有保存Cookie或者登录过Google没有都可以保证你在访问任一Google页面时是登录的。而缺点就是一旦启用了脚本后就无法登出了，因为登出后会再次登录。如果你实在想登出的话，那么你只需要点一下Firefox中的小猴子暂时禁止GreaseMonkey，然后再登出就可以了。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-7118105271204706071?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/7118105271204706071/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/12/google.html#comment-form' title='1 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7118105271204706071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7118105271204706071'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/12/google.html' title='Google帐号自动登录脚本'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-672041450083846142</id><published>2008-11-28T22:17:00.003+08:00</published><updated>2008-12-17T20:19:12.697+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='Newegg'/><category scheme='http://www.blogger.com/atom/ns#' term='GreaseMonkey'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><title type='text'>Newegg Hidden Price Revealer</title><content type='html'>&lt;p&gt;最近在研究jQuery的时候突发奇想，想起了前段时间看过的GreaseMonkey。突然想用jQuery写一个GreaseMonkey脚本试试看，看看到底jQuery能有多强大。&lt;/p&gt;

&lt;p&gt;随意浏览了一下各个网站，发现Newegg.com有个我可以做做文章的内容。Newegg.com上有一些产品的价格信息是隐藏起来的，只有当你点击相应的链接后才会在弹出窗口中显示出真实的价格来。那么我想了一下，是否可以做这样一个GreaseMonkey脚本，使我不用点击链接就直接可以在当前页面上看到真实价格呢？&lt;/p&gt;

&lt;p&gt;说干就干，随即在Firebug的帮助下完成了这样一个显示隐藏价格脚本的编写。目前这个脚本我已上传到了&lt;a href="http://userscripts.org/" target="_blank"&gt;userscripts.org&lt;/a&gt;上，有需要的朋友可在下面链接得到：&lt;/p&gt;

&lt;p&gt;&lt;a href="http://userscripts.org/scripts/show/37731" target="_blank"&gt;Newegg Hidden Price Revealer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Screenshots:&lt;/p&gt;

&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_TtUDCDHbyoo/STCTiFYfgXI/AAAAAAAABJk/dPDIArl2V0E/s1600-h/hidden_price.gif"&gt;&lt;img style="margin:0 10px 10px 0;cursor:hand;width: 400px; height: 289px;" src="http://2.bp.blogspot.com/_TtUDCDHbyoo/STCTiFYfgXI/AAAAAAAABJk/dPDIArl2V0E/s400/hidden_price.gif" border="0" alt="Image showing the original hidden price" /&gt;&lt;/a&gt;&lt;br/&gt;
原始的价格隐藏产品页面&lt;/p&gt;

&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_TtUDCDHbyoo/STCUZqPBxHI/AAAAAAAABJs/glVw2I3n6ss/s1600-h/revealed_price.gif"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 288px;" src="http://2.bp.blogspot.com/_TtUDCDHbyoo/STCUZqPBxHI/AAAAAAAABJs/glVw2I3n6ss/s400/revealed_price.gif" border="0" alt="Image showing the revealed price" /&gt;&lt;/a&gt;&lt;br/&gt;
真实的价格被显示出来了&lt;/p&gt;

&lt;p&gt;下面描述一下这个脚本的实现过程，以供读者和我本人日后参考。:)&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;首先用Firebug查看有这种隐藏价格的产品页面，用Inspect功能点击显示价格的链接，找出这种隐藏价格的特征。这样就能识别哪些内容是隐藏价格的内容了。&lt;/li&gt;
    &lt;li&gt;因为点击链接后会弹出新窗口，而我们需要的真实的价格正是在这个新窗口中，所以需要首先找到这个窗口的URL。可以在我们上面定位到的链接中找到，也就是脚本需要提取这段URL。&lt;/li&gt;
    &lt;li&gt;拿到了URL后就要写一个Ajax调用拿到这个URL的响应，返回的内容自然是HTML，所以需要在这个HTML返回里找出真实的价格信息的特征。&lt;/li&gt;
    &lt;li&gt;找到特征后，利用特征提取真实的价格信息，然后用这个真实的价格信息替换原始的链接，这样就完成了脚本的编写了。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;整个脚本由于有jQuery的帮忙所以所需的代码量很小。结论是jQuery真的很强大，真的符合它的设计理念：“Write less, do more.”&lt;/p&gt;

&lt;p&gt;注意事项：这里需要注意如果原本页面中就有引用jQuery类库的话那么我们在GreaseMonkey中就不要再引用了，会出现问题。所以在脚本中需首先判断jQuery对象是否已经存在。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-672041450083846142?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/672041450083846142/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/11/newegg-hidden-price-revealer.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/672041450083846142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/672041450083846142'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/11/newegg-hidden-price-revealer.html' title='Newegg Hidden Price Revealer'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_TtUDCDHbyoo/STCTiFYfgXI/AAAAAAAABJk/dPDIArl2V0E/s72-c/hidden_price.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-1968197257835992615</id><published>2008-11-14T17:13:00.002+08:00</published><updated>2008-11-15T08:47:18.172+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TechED'/><title type='text'>TechED北京——结束日</title><content type='html'>&lt;p&gt;TechED北京的最后一日会给我们带来什么样的惊喜呢？让我们来看看我接触的一些主题：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BI的未来之路&lt;/li&gt;
&lt;li&gt;社区活动，听王老师讲课&lt;/li&gt;
&lt;li&gt;使用OBA整合LOB应用&lt;/li&gt;
&lt;li&gt;Do these ten things or else get 0wn3d&lt;/li&gt;
&lt;li&gt;虚拟化的安全性&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;BI的未来之路&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;标题有些唬人了，其实这里所讲的只是面对非专业BI人员在需要一些BI功能时可以有的选择，当然讲师讲的是微软产品。也就是，像我们这些不懂BI的人想要自己做一些数据挖掘的话那么就可以用这里提到的产品来试试看了。简单地说微软就是想把Excel当作这个简单的BI工具，在Excel的基础之上提供一套简化的BI工具。它的名字是Gemini。&lt;/p&gt;

&lt;p&gt;微软的逻辑是这样的，不会有很多人懂得BI，但却有许多人需要BI，每当我们需要一些BI功能的时候我们总是要去找专业人员帮忙解决，哪怕只是很简单的一些功能。那么我们是否可以自己动手满足自己的这些小需求呢？这就需要一个比较简单的，大家都熟悉的软件了。基于这套推理，Excel自然成为了最佳选择，不过它本身还不够满足BI需求，所以微软在Excel之上提供了Project Gemini，一个比较强大的Analysis套件。BTW，微软还会在2010年上半年推出&lt;strong&gt;SQL Server Kilimanjaro&lt;/strong&gt;，一个面向BI功能的SQL Server特殊版本，注意它不是SQL Server的下一个版本，而是一个特殊版本。这个特殊版本可以处理微软定义的三个级别的BI需求并集成管理它们，这三个级别分别是：Personal, Team, Corporate。这三个级别来自于三种不同的需求场景，一个是作为个人我需要一些BI，一个是作为Team我们有我们自己的BI需求，而另一个则是整个企业的BI需求。当然后期还可以promote到更高的级别，比如个人的BI需求如果Team觉得好就可以集成到Team的BI处理中。&lt;/p&gt;

&lt;p&gt;关于Excel作为BI工具，讲师一再强调这是一个给ocassional user使用的工具，不是给专业BI人员使用的工具。同时还提到了几个Gemini的特色，如下：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Column Based&lt;/li&gt;
&lt;li&gt;In-Memory Storage&lt;/li&gt;
&lt;li&gt;Integrated into Excel&lt;/li&gt;
&lt;li&gt;SharePoint Collaboration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;其它的特性还有基于组件的self-service reports，组件是可复用的单元等等。总的来说看起来还可以试一试，虽然Gemini目前并不是一个被微软支持的软件，甚至还没有发布。微软目前的打算就是让大家到时候试试看，好了您就买，他们就发展。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;社区活动，听王老师讲课&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;王老师大家都知道是谁吧？VSTS的主题我们都听王老师讲过N遍了，其他的我就不多说了，单说这人气真可谓是旺。虽然可能我们大家都听过不少VSTS的讲座了，但是对于其他人来说却是一个很好的机会了解VSTS能做啥。&lt;/p&gt;

&lt;p&gt;提一个无关紧要的趣事，本次TechED搞了一个小活动，叫“寻找你身边的MVP”。就是给你发一个单子，上面有不少知名MVP，你找到他们让他们给你印个章，凑够六个可兑换精美礼品一份。话说王老师就在此名单上，所以我们一路行走遇到无数“包围圈”，硬生生把我逼出了“圈”外不知道多少回。欲知详情，请直接咨询王老师。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;使用OBA整合LOB应用&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;这基本上是一个讲Office应用的session。在每个公司内部都有很多流程与应用，我们称之为OA，用软件的方式自动化它们。那么微软推崇的一种做法是利用Office程序作为应用程序界面，以BizTalk、Workflow和WCF Service为后台流程扭转机制来实现业务流程自动化。选择Office是因为它易用、它知名，很多人用Office比我们开发人员用的熟练，Office对于他们来说是家常便饭，很熟悉的一个软件，就像Visual Studio对于开发人员一样。这有几个好处，那就是培训成本低了，因为用户都已经会用了，而且很熟悉；支持成本低了，这也是基于上述的道理；用户体验变好了，因为对于最终用户来说，有一个Office界面他们已经很满足了，Office的操作方式对于他们来说体验是最好的了。&lt;/p&gt;

&lt;p&gt;如果是人机交互的流程应用，那么微软建议我们使用WF+MOSS来实现，这样也可以和其他的Office程序进行集成。要说用Office做程序的第二大优势就是它的高集成性（第一大是它的知名度，还记得吗）。另外讲师除了讲这些概念外还演示了一个Office应用，从后台拿数据到前台展示都涵盖的一个应用，不过并没有演示源代码。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do these ten things or else get 0wn3d&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;我保留了这个原版的英文标题是因为这个session太帅了，个人觉得这是今年TechED最好的讲座。讲师是Steve Riley, Microsoft Senior Security Strategist。此人平时看起来就是一个穿着随意的老外，但一旦开始演讲后就变了，非常有人格魅力，特别诚恳，可以看出完全是对听众负责、准备的特别周全的一个人，特别风趣并且不站在讲台上讲，而是走到下面站在第一排听众座位前走来走去地讲，非常有激情而且PPT非常酷，很多的动画效果，非常的通俗易懂。哦，还有，非常可惜的是你我都已经再也看不到原版PPT了，TechED和网上能下载到的PPT都是For Publish版的，删掉了若干页面，精华啊！不用猜也知道被删减的原因是由于里面有一些“有趣”的图片和文字内容，幸好我有幸看到了他本人的原版PPT，可惜我不是一个画家，否则一定帮大家画出来。Steve这次的行程也是非常的匆忙，前几天在欧洲几个国家巡回演讲，今天（TechED第三日）又飞到北京进行下午的两场演讲，而晚上就要离开飞到另一个国家继续演讲，真是比谁都忙啊。&lt;/p&gt;

&lt;p&gt;好了，言归正传，Steve也说过本次的讲座并不是一个告诉你该怎么做才会安全的一个check list，他本人也并不喜欢check list式的安全做法，他认为你应该懂security才能做好security，光靠一个check list是远远不够的，原因很简单，因为没有一个零安全问题的软件、网站存在，只是被发现的时间早晚而已。假设如果有人或企业能够做出零安全问题的软件的话，那么它将永远都不会被投入使用，因为它将需要无限的资源、时间去测试。这一点和bug是一样的，没有一个软件、网站是零bug的，只是被发现的时间早晚而已。所以你需要懂它才能正确的处理各种情况。&lt;/p&gt;

&lt;p&gt;首先Steve介绍了“我们”和“他们”的区别，当然“我们”是指Good Guys，“他们”是指Bad Guys。结论很明显，做good guy要比做bad guy难很多，各方面都是bad guys胜出，听到这里也许你会想，“嗯，我应该马上去hack我的邻居了”。好吧，Steve会告诉你，“我做security是因为我觉得更有挑战”。&lt;/p&gt;

&lt;p&gt;接下来Steve和我们分享说做security首先用对词汇，用正确的词汇才能表达正确用意，否则会产生理解上的偏差，当然，这对我们做开发的人来说也是一样。这里给大家分享一个Steve给出的公式，你在TechED的PPT上是找不到这个公式的，由于某些我不清楚的原因，TechED的PPT有很多删减。这个公式是Steve很推荐的一个公式，因为它很简单但却很实用。&lt;strong&gt;R = T * V * E&lt;/strong&gt;，R代表Risk，T代表Threat，V代表Vulnerability，E代表Exposure。Threat要么是0要么是1，代表是否有bad guys想要侵犯你的系统；Vulnerability是一个从0到1的小数，代表你给出的一个衡量自己系统脆弱性的一个数值，你需要用你自己的标准来测量出这个数值；Exposure是一个数量单位，你的系统有多少个暴露处这个数值就是多少。由此可以计算出你系统的Risk，将risk与一个cost指数相乘你就可以得出说我现在的系统如果出现安全问题的话我大概会需要多少成本能够解决掉它，那么你就可以优先注重解决那些高成本的安全问题了。很酷！&lt;/p&gt;

&lt;p&gt;Steve给good guys的一些建议。从心理上，你需要接受没人喜欢你这个事实，因为别人会把你想成那种整天都是天要塌下来的感觉。其次，你需要注意不要经常给人这种“什么都不能干”的感觉，别人会排斥你的，你需要随时注意“Protection, not restriction”原则。例如Steve本身就非常不喜欢别人限制他，尤其是在公共场所因为一些无聊的规则被限制（也可以说他是一个很有个性的人）。另外，Steve建议省省你的骄傲，多订阅一些安全网站和文章，你会发现比你更牛的人有的是，向人学习总比向人显摆自己很牛要实际得多。这对于开发人员来说也适用，技术是学不完的，不要太要面子，总摆出一副很牛的样子让人敬畏，多向人请教请教你会发现别人比你强得多。&lt;/p&gt;

&lt;p&gt;将你自己想象成一个bad guy会有助于预防安全隐患，这很容易想象。同样对于开发人员来说也适用，在写代码的时候多想想用户会怎么用，怎样的边界会被输入等，这有助于测试和安全防患。&lt;/p&gt;

&lt;p&gt;不要太过相信各种厂商给你做的产品演示，说什么用了他们的产品就可以再不用担心这方面的安全问题之类的话，没有人敢说100% secure，他们只是在推销而已。没有任何产品、书籍、解决方案或讲座可以解决你所有的安全问题，每种情况都是不一样的，Again，你需要相信的是一群懂security的人而不是一堆的工具。这点同样适用于软件开发，工具再好也没有人实用，真正的expert比任何工具都更可靠。&lt;/p&gt;

&lt;p&gt;Steve还和我们分享了其他的一些精彩内容，大家可以去翻翻PPT，真的很可惜最全的原版再也看不到了，早知道当初应该向他要一份copy的。里面还有一些关于思考的内容，例如其中一张是酒店里通用的做法：将手纸的起始处折成三角形。Steve问为什么所有的酒店都是这样做？有什么意义？还是我们只是一味的抄袭？你是不是觉得check list就有点这种不知道为什么要做只是别人都做我也做的感觉呢？&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;虚拟化的安全性&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;很高兴这一session还是由Steve主持的，关于Steve大家通过我的文字可能对他都有了一定的了解，我就不再描述了。这里所指的安全性主要还是围绕着Windows Hyper-V展开的。他很生动的描述了Hyper-V的体系结构以方便我们了解它的一些安全特性与做法。由于这些内容有很多，如果大家对此感兴趣可详细看下PPT中的内容。Steve从在普通系统中我们如何做安全讲到VM有哪些不同，最后得出一个结论：VM的安全性与普通系统无区别，你平时怎么做安全VM后还是怎么做。-_-! 不过要注意Hyper-V中的Root有最高权限和影响Hypervisor的能力，所以不要用Root来运行任何程序以防止它被控制从而导致Hypervisor被控制。Hypervisor被控制意味着所有跑在Hypervisor上的VM都被控制。&lt;/p&gt;

&lt;p&gt;Steve还share了一些有趣的数据，如下：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;根据微软数据显示，Windows 40%的蓝屏是显卡驱动导致的。&lt;/li&gt;
&lt;li&gt;你知道微软收集的大量的cracker code一般是怎么来的吗？通过被crack程序崩溃时发送到微软的crash报告，里面甚至有cracker所使用的每一句assembly指令。微软通过这些内容来辅助分析安全问题。&lt;/li&gt;
&lt;li&gt;Steve建议一旦有security patch一定要第一时间打上，原因大家都知道。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;好了，这基本上就是全部TechED三天来的收获，如果大家想知道更详细点的话可以线下再与我交流或者仔细阅读PPT。另外在美国举行的PDC2008也有非常多的很棒的内容，大家可以在网上找录像来看。TechED北京的录像不知道会有多少，等出来了大家可以去挑自己感兴趣的去看看。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-1968197257835992615?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/1968197257835992615/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched_8378.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/1968197257835992615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/1968197257835992615'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched_8378.html' title='TechED北京——结束日'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-7061855404409900575</id><published>2008-11-14T13:26:00.001+08:00</published><updated>2008-11-14T13:39:19.491+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TechED'/><title type='text'>TechED北京——第二日</title><content type='html'>&lt;p&gt;北京TechED已经结束有几天了，不好意思这么晚才给出第二日的博客。那么让我们进入主题，第二日的一些有意思的主题如下：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IE 8的一些新特性&lt;/li&gt;
&lt;li&gt;Workflow Foundation 4.0新特性&lt;/li&gt;
&lt;li&gt;Windows下利用WinDBG和DebugDiag来调试程序问题&lt;/li&gt;
&lt;li&gt;微软新技术演示大串烧&lt;/li&gt;
&lt;li&gt;嵌入式Silverlight&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IE 8的一些新特性&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;讲师将IE 8的一些新特性大致分成了User Experience，Engine和Management几类，我觉得倒是没有必要详加分类，所以这里我就不按照分类来总结这些新特性了。另外一些管理方面的特性，如定制化的IE安装包，企业中的几种部署等与我们日常使用IE 8和IE 8开发都没什么关系所以我们这里也就不看了。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web accelerators&lt;/li&gt;
&lt;li&gt;Web slices&lt;/li&gt;
&lt;li&gt;By tab crash recovering&lt;/li&gt;
&lt;li&gt;Visual search engine&lt;/li&gt;
&lt;li&gt;Adaptive Zooming&lt;/li&gt;
&lt;li&gt;Windows Defender integration&lt;/li&gt;
&lt;li&gt;Domain name highlight&lt;/li&gt;
&lt;li&gt;Per user ActiveX&lt;/li&gt;
&lt;li&gt;Per site ActiveX&lt;/li&gt;
&lt;li&gt;Standard compliant&lt;/li&gt;
&lt;li&gt;Compatibility view&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;所谓的Web accelerator其实是一些加在文字或链接上的右键菜单，弹出后可以根据被选中文字或链接提供一些有用的选项，譬如我选中“九阳豆浆机”三个字然后右键弹出菜单后选择“新蛋”子菜单再选择“购买”或“搜索”，又或者是“报价”，那么这时就会在新的Tab中弹出新蛋的相关页面。当然这些是要新蛋提供相应的Web accelerator并且用户下载安装才可以实现的。&lt;/p&gt;

&lt;p&gt;Web slices是一种bookmark，可以将一个链接放在工具栏中，当你点击它的时候它会弹出一个小下拉窗口展示这个链接的内容。这个功能比较适合那种需要经常“看一眼”的网页。&lt;/p&gt;

&lt;p&gt;IE 8的每个页面都展示在tab中，据说每个tab都是独立进程，所以当一个tab死掉的时候不会影响其它的，也就是，IE不会由于一个tab崩溃。另外还有crash recovering，用过Firefox的朋友自然都知道是什么。关于每个tab是一个进程的问题社区中经常有争议，认为会过多消耗资源，和IE 6没什么两样。&lt;/p&gt;

&lt;p&gt;用过Firefox和IE 7的朋友都知道有一个搜索引擎下拉框，可以用来进行搜索引擎的选择。在IE 8中这个框有了新的扩展功能，可以支持返回结果带有图片之类的多媒体，所以叫做Visual Search Engine，不过这需要各个厂商自行实现图片的返回以及处理。在我看来这个功能不怎么会火，也不会有多少人去用。&lt;/p&gt;

&lt;p&gt;一个小增强，在Zoom In的时候多出IE宽度的内容会被“很好”的重新布局成不超出宽度的页面。演示时没有成功，看来也要看页面的HTML和CSS啊。个人觉得这是一个自作聪明的功能，比较鸡肋。&lt;/p&gt;

&lt;p&gt;与Windows Defender集成预防trojan一类的功能是见仁见智了。（我个人根本就不开Windows Defender）域名高亮的功能实在是好，希望我的Firefox也有这样的功能。简单地说这也是一个防钓鱼的措施，可以将一个URL的域名部分高亮显示出来，防止钓鱼者给你一些混淆耳目的URL引你上钩。例如"http://www.playboy.com%40%77%77%77%2E%68%61%63%6B%2E%63%6F%6D"这个URL就是一个钓鱼URL，域名并不是playboy.com。&lt;/p&gt;

&lt;p&gt;ActiveX一直都是IE下安全隐患最大的功能，在IE 8中，微软提出了per user和per site两种策略来尽可能降低使用ActiveX的风险。per user是说用户下载安装的ActiveX以这个当前用户的身份来运行，那么如果这个用户并不是Administrator那ActiveX的执行就相对安全多了，即使出问题也只是这个用户受影响而已。per site防止的场景是说如果你从A网站下载了一个ActiveX，那么当你访问一个B网站的时候它也有可能会去运行这个ActiveX，例如Flash正是这样的。这个ActiveX是完全有可能有安全隐患的，一旦被B拿去调用很有可能会造成严重的安全问题。其实这里说的是，你信任A网站，但你不信任B网站，所以在IE 8中你可以设置说只有A网站才能运行这个ActiveX而B网站不可以。这两个ActiveX的保护措施都是非常不错的。&lt;/p&gt;

&lt;p&gt;IE 8终于Claim它可以很好的支持Web Standard了，也就是，我们在Firefox等其他浏览器上看到的网页也都可以很好的展示在IE 8中了。这是一个很好的消息，不好的消息是这样做会break掉很多以往专为IE开发的网页。微软对这种问题的补救措施就是所谓的Compatibility View按钮，当你发现某个网页显示不正常的时候就用这个按钮切换到以往的渲染方式吧。不过目前来看这个按钮有很多问题，兼容的还不是很好。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workflow Foundation 4.0新特性&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;讲师稍微讲了一下WF的主要组成部分如Activities, Runtime和Tools。同时又大力宣传WF 4.0的各项增强，告诉我们这对我们来说有多么多么的好，不过由于时间有限，大部分的新特性都没有演示，只是口头提及了一下。我总结了一下，大致如下：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;设计器的rehosting变得更简单了，可以很简单的在VS和我们自己的程序中嵌入WF的设计器，而不再像现在这样麻烦了。&lt;/li&gt;
&lt;li&gt;变量的Scope变化，变量的Scope缩小了，4.0中只能访问自己和Parent。据说这样可以简化workflow的runtime management和缩小内存占用。&lt;/li&gt;
&lt;li&gt;条件表达式在4.0中也成为一个activity了。&lt;/li&gt;
&lt;li&gt;性能提升，据说会有10-100x的运行性能提升。&lt;/li&gt;
&lt;li&gt;Partial Trust的支持。&lt;/li&gt;
&lt;li&gt;可控制的存储，可以使我们很方便的替换存储。&lt;/li&gt;
&lt;li&gt;设计器由WPF制作，功能更强。&lt;/li&gt;
&lt;li&gt;由于表达式也成为了Activity，现在的调试体验更好了。&lt;/li&gt;
&lt;li&gt;新增了一种workflow类型：FlowChart。也就是现在有三种了：Sequential, State Machine和FlowChart。FlowChart比较类似Sequential，主要针对于人机交互的这种workflow。&lt;/li&gt;
&lt;li&gt;更好的WCF Service机制，可以完美的暴露或调用WCF Service。&lt;/li&gt;
&lt;li&gt;全XAML化支持，你现在可以完全用XAML制作一个workflow出来而不用写一行代码。同样也可以完全用XAML描述一个workflow使其暴露成一个service。&lt;/li&gt;
&lt;li&gt;持久化的duplex communication在4.0中有支持，异步通讯从此畅通无阻。&lt;/li&gt;
&lt;li&gt;Message correlation在4.0中完全通过消息（Message）实现了，这更灵活，不像现在利用cookie的机制一样限制很大。&lt;/li&gt;
&lt;li&gt;不同版本的workflow可以很好的side-by-side运行。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;可以看出4.0的WF的确很好很强大，不过坏消息是4.0的WF还得等上一阵子，预计2010年发布，看看是否能提前到09年下半年吧，让我们拭目以待。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows下利用WinDBG和DebugDiag来调试程序问题&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;这是一个非常有意思且具有实用价值的一个session，讲师来自专业技术支持团队，整天都在和调试打交道，用的工具自然也都是绝对Professional的。这里她提到了两个工具，WinDBG和DebugDiag，都是我以前接触过的，但是就没有人家那么专业了。讲师介绍了很多WinDBG的指令和几种常见的程序问题情况，如高CPU如何调试，程序无响应如何调试，内存泄漏如何调试等。当然造成这些问题的原因有很多，不是一两个演示就可以涵盖的。&lt;/p&gt;

&lt;p&gt;这两个工具和其背后的原理涉及到大量的指令演示和Windows的一些底层原理，所以这里就不给大家详细介绍了，也许今后有机会我会写一些这方面的博客吧。很感兴趣的朋友可以去看一下这个session的slides和在网上搜一些资料，有很多。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;微软新技术演示大串烧&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;轮流演示了一些用微软新技术实现的产品或网站。演示有以下几个：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Popfly&lt;/li&gt;
&lt;li&gt;VS2010中的WPF Tree Visualizer。&lt;/li&gt;
&lt;li&gt;几个Silverlight很酷的Demo，属于纯炫耀。&lt;/li&gt;
&lt;li&gt;Photosynth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Popfly以前也有听说过，不过从演示来看就是一个小游戏编辑器，我后来看了一下官网，好像也没看到什么有用的地方，搞不懂。&lt;/p&gt;

&lt;p&gt;Photosynth以前也有听说过，简单地说就是你围绕一个场景拍N多张有部分重叠的照片，然后这个软件会帮你从各个匹配的角度进行拼接形成一个3D模型，之后你就可以通过这个3D模型对这些照片进行浏览了。官网上有很多建好的很酷的模型，不过真要是自己用恐怕有点不实际。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;嵌入式Silverlight&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;这个session就是一个忽悠的session，讲师讲了一堆与嵌入式Silverlight无关的话题，什么用户体验有多么重要了之类的，最后只提到了一点相关的，那就是嵌入式版本的Silverlight将是一个native runtime，而并非是基于现有的.NET平台的，这是出于大小和性能的限制做出的决定。当然从用体验上应该差别不会特别大，这是开发的时候就会和以往有一些不同了，具体怎么不同也没有说明，而且这个嵌入式Silverlight现在也还很遥远，基本上可以说我们现在不要对嵌入式版本的Silverlight报什么太大期望。&lt;/p&gt;

&lt;p&gt;OK，大体上就这么多内容，欢迎各位补充或评论。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-7061855404409900575?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/7061855404409900575/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched_14.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7061855404409900575'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7061855404409900575'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched_14.html' title='TechED北京——第二日'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-2205370684778104766</id><published>2008-11-06T22:30:00.003+08:00</published><updated>2008-11-07T20:18:50.144+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TechED'/><title type='text'>TechED北京——第一日</title><content type='html'>&lt;p&gt;第一日主要都是主题演讲，所谓的主题演讲，其实就是微软对外宣传他们产品的一种机制，借这个机会向广大技术人员公布和宣讲一些微软新技术、新产品。主题演讲一般是以介绍的形式推进的，所以不会涉及到过多的技术细节，而是专注于Features的介绍，展示此产品的一些最大特色。那么本次TechED为大家带来的都是什么主题呢？&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Hyper-V&lt;/li&gt;
  &lt;li&gt;Cloud Computing&lt;/li&gt;
  &lt;li&gt;Windows Azure&lt;/li&gt;
  &lt;li&gt;Live Mesh&lt;/li&gt;
  &lt;li&gt;Windows HPC Server&lt;/li&gt;
  &lt;li&gt;UX - WPF, Silverlight, Surface&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Hyper-V&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;在Hyper-V的演讲中，微软拍了一部短片播放给大家，内容是一个IT经理的一天。“IT经理的一天是忙碌的，从早到晚有不断的IT问题找到他，他需要与这些人沟通并解决这些问题，但往往硬件与软件资源本身的特性使得这些事情都很不好在短时间内很好的解决，导致问题的积累，忙碌的一天就这样过去了，而明天还将如此”。好，接下来就该微软的超级产品Hyper-V出场来帮助这位已经到达了现场的“IT经理”来帮助他提升工作效率解决这些烦恼了。&lt;/p&gt;

&lt;p&gt;Hyper-V是一套企业级的虚拟化解决方案，对于IT经理来说自然有一些世人皆知的好处，比如硬件资源的开支节省，更方便集中的管理等。在“IT经理”与微软技术专家的谈话中我们可以看到Hyper-V的一些最大特点，例如虚拟系统的资源占用是可以通过设置来调配的，这一点可以很好的使IT经理把握硬件资源的使用，不至于一台虚拟系统过多的占用硬件资源而导致其他优先级更高的系统瘫痪。另外通过两人的对话我们也得知Hyper-V在动态的资源管理上有着不小的好处。例如，当物理机器的CPU达到100%时，它所host的其中一些虚机就会自动的切换到另一台比较空闲的host上去，这样可以有效的缓解压力，使host再活回来。同理，在发生fail的情况下，虚机也会被切换到另一台舒适的host上去以保证整体系统的高可用性。&lt;/p&gt;

&lt;p&gt;另外在应用程序虚拟化上，Hyper-V更是可以做到一个虚拟系统上同时可以跑多个版本的同一程序，例如IE6、IE7和IE8同时出现在一台虚机上供用户使用。当然并不是真正的在用户的虚拟系统中安装这些不同的版本，我们知道有些程序的不同版本本身就是有冲突的，不能同时安装在一起；Hyper-V是通过管理员的配置有选择性的提供给你一些管理员已安装好的各个程序供你使用，这些程序实际上被安装在不同的系统中。你可以把这些并存的程序想象成是远程的程序，但是它们的一般交互看起来却像是在本地一样。当然，管理员还可以管理权限的分配，哪些程序哪些人可以实现哪种级别的交互都是可以被定义的。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloud Computing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;云计算不仅仅是微软在推的一项技术，而是整个业界都普遍在推动的一项技术。简单说来就是绘制一个大型的虚拟空间，可以为我们提供“无限”的存储与计算。由于云是动态扩展的，可以通过热插拔来提升硬件能力，所以它看起来像是可以无限提供计算能力的一个东西。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows Azure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;微软的第一个云操作系统，你可以将其想象成一个在线的提供服务的操作系统hosting。你可以用它的SDK开发出基于云的程序（服务）然后部署上去，在你的quota允许的范围内使用资源。当然当你的业务发展到一定程度后，你的资源需求也会变大，那么这时你需要做的就是增加你的quota就可以获得更多的可使用资源了（CPU、Memory）。而且你可以享受一切虚拟化所带来的好处。&lt;/p&gt;

&lt;p&gt;当然，天下没有免费的午餐，好东西总是有一个高昂的代价。托管的服务平台意味着你要将你自己的程序交给微软，由微软替你保管并且帮助你运行。对于大公司而言，将自主开发的成果交给另一个公司托管是很不明智的，所以个人觉得Windows Azure更适合小型企业，它帮助小型企业免去了高昂的IT维护费用和程序、资源扩展所带来的麻烦。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Live Mesh&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;谈到云计算，不得不提微软的Live Mesh。对于最终用户而言，Mesh是一个大型的在线存储服务，我们可以上传下载文件。对于开发人员而言，它也是一个大型的存储服务，云存储，可“无限”增长的、可靠的存储。只不过，它有API，这就使得我们可以围绕这个在线存储做很多文章出来，例如将手机上拍的照片通过Mesh的手机版客户端（API）在后台“悄悄”的传到Mesh上，然后由另一台机器上的程序将已上传到Mesh上的照片下载下来使用，相当于一个自动同步的过程。&lt;/p&gt;

&lt;p&gt;当然这一切看起来也没有那么不可思议，Mesh只不过是多了几种设备的客户端而已。但创意，却掌握在你自己手中。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows HPC Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;对于这一产品，本次的主题演讲中倒是没有过多的演示，只是拿一个围棋游戏为例，说明了HPC Server的并行计算能力，通过“plug”多台机器上来达到提升运算效率的结果。没有讲编程模型，给人的感觉是编程方面相当的复杂，个人还是更期待.NET 4.0中的Parallel Framework。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UX - WPF, Silverlight, Surface&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;最后的这个关于用户体验的演讲有点长，但是并不是想象中围绕用户体验本身做的讲解，而是一再强调用户体验对于我们企业来说是多么有用、多么重要，而我们可以怎样通过微软的各种工具来改善我们所做程序的用户体验。那实现增强用户体验的工具自然就是WPF、Silverlight这种我们已经还算熟悉了的技术。&lt;/p&gt;

&lt;p&gt;另外微软还现场演示了一下Surface，据称其中文名是“神桌”。-_-! 演示的内容还包括开发一个简单的Surface程序，当然用的是WPF。这里还有描述说Surface所支持的多点触摸（Multi-Touch）将在将来集成在Windows的基础API中，或者WPF 4.0中，那么到那时Windows也将是一个支持多点触摸的一个操作系统，也可以用WPF来开发多点触摸的程序了。&lt;/p&gt;

&lt;p&gt;BTW, Surface在PC上有个模拟器。也许你会问，如何在模拟器上模拟多点触摸操作呢？答案可能出乎你的意料，不过却很简单，那就是，多插几个鼠标。+_+&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-2205370684778104766?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/2205370684778104766/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched.html#comment-form' title='1 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/2205370684778104766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/2205370684778104766'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/11/teched.html' title='TechED北京——第一日'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-1818352947334736541</id><published>2008-10-24T16:57:00.001+08:00</published><updated>2008-10-25T08:38:41.511+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian手记——CryptoUtility使用说明（高阶）</title><content type='html'>&lt;p&gt;在特殊场景下可能你的程序不方便使用App.config或Web.config（比如你将这些配置信息都存在数据库中）。这时你就需要用到下面介绍的几个CryptoSession的构造函数了。&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; CryptoSession(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; CryptoSession(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; keyNamePrefix);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; CryptoSession(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; password, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; keyName, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isKeyNamePrefix);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;这三个构造函数做的事情与使用配置文件时一样，当你不能使用配置文件时就使用这几个构造函数吧。不过另外还有一个构造函数，如下：&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; CryptoSession(IAccountProvider accountProvider, IKeyNameProvider keyNameProvider);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;这个构造函数非常Powerful，如果你有极特殊复杂的帐号信息获取逻辑的话那么可实现IAccountProvider和IKeyNameProvider这两个接口来向CryptoSession提供帐号信息和key name，注意这里提供的key name必须是完整的，而不能仅仅是prefix。&lt;/p&gt;

&lt;p&gt;讲过了上面几种不同的构造方案后我们再来看一下CryptoSession的Open方法和Close方法。&lt;/p&gt;

&lt;p&gt;Open方法会创建一个与Ingrian服务器交互的上下文（Context），并且会通过我们提供的key name来获取到Ingrian服务器上的&amp;#8220;key对象&amp;#8221;。在任何加解密操作前这个上下文和&amp;#8220;key对象&amp;#8221;都应该是已经存在的，也就是，像SqlConnection一样，在操作前必须先调用一下Open方法。不过，在&lt;a href="http://world-coded.blogspot.com/2008/10/ingriancryptoutility.html"&gt;基础篇&lt;/a&gt;中我们所给出的代码片段中就没有调用Open方法，这是因为CryptoSession会自动判断，如果没有Open过的话它会自己先Open一下。&lt;/p&gt;

&lt;p&gt;顾名思义，Close方法就是把这些资源都释放掉的一个方法，Close后可再Open。如果不调用Close方法便再一次调用Open的话，Open会自己调用一遍Close方法以释放原有的资源。可能你会想，为什么要这么做呢，这不是多余吗？其实不然，这就是另一个高阶使用技巧。当你Open一段时间后，可能会出现因为某些原因&amp;#8220;key对象&amp;#8221;或者当前这个上下文会失效或者丢失的情况，当你有这样的怀疑时，你可以捕获异常，在异常处理中再Open一次，这样原有的资源会被释放掉，新的，有效的上下文和&amp;#8220;key对象&amp;#8221;会被获得。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-1818352947334736541?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/1818352947334736541/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_5534.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/1818352947334736541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/1818352947334736541'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_5534.html' title='Ingrian手记——CryptoUtility使用说明（高阶）'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-6314903691910678340</id><published>2008-10-24T16:16:00.002+08:00</published><updated>2008-11-04T10:56:17.969+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian手记——CryptoUtility各项限制</title><content type='html'>&lt;p&gt;Ingrian本身的API有一些限制，会影响到CryptoUtility，组件自身也有一些限制，所以在这里对这些使用限制做一个集中描述。&lt;/p&gt;  &lt;p&gt;CryptoUtility组件中所使用的key name是有限制的，key name的整体长度不能超过15个ASCII字符。但由于使用时我们可以只指定前缀（prefix）部分，所以在这种情况下prefix的实际长度不能超过8个字符，因为在prefix之后会占用7个字符。 &lt;/p&gt;  &lt;p&gt;一次加解密动作的数据量是有限制的，每次操作的byte数不能超过167,999。如果你加解密的是字符串的话需注意byte数是以UTF8解码后的byte数计算的。&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-6314903691910678340?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/6314903691910678340/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_7077.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/6314903691910678340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/6314903691910678340'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_7077.html' title='Ingrian手记——CryptoUtility各项限制'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-689828889350672840</id><published>2008-10-24T16:05:00.001+08:00</published><updated>2008-10-25T08:39:48.113+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian手记——CryptoUtility配置详解</title><content type='html'>&lt;p&gt;CryptoUtility并没有多少配置信息，因此它仅有的一些配置项也都很简单。&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;&amp;lt;!-- User name used to connect Ingrian servers, required. --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.userName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;sampleUserName&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #008000"&gt;&amp;lt;!-- Password used to connect Ingrian servers, required. --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;samplePassword&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     &lt;span style="color: #008000"&gt;&amp;lt;!-- Key name used in cryptographic operations, optional.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; &lt;span style="color: #008000"&gt;         If you do not provide one and nor you provide a&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt; &lt;span style="color: #008000"&gt;         key name prefix, the component will use a default one. --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.keyName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;sampleKeyName&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     &lt;span style="color: #008000"&gt;&amp;lt;!-- Key name prefix used to construct a key name for&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; &lt;span style="color: #008000"&gt;         cryptographic operations, optional. If you do not&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt; &lt;span style="color: #008000"&gt;         provide one and nor you provide a key name, the&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt; &lt;span style="color: #008000"&gt;         component will use a default key name. --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.keyNamePrefix&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;sampleKeyNamePrefix&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;ingrian.userName是必须提供的，在与Ingrian服务器连接时使用。 &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;ingrian.password是必须提供的，在与Ingrian服务器连接时使用。 &lt;/li&gt;

  &lt;li&gt;ingrian.keyName是可选的，指定各项操作时用的key name。如不提供，CryptoSession会再去找ingrian.keyNamePrefix这个配置项的内容，如有，就使用这个prefix，如没有，就使用组件默认提供的key name。 &lt;/li&gt;

  &lt;li&gt;ingrian.keyNamePrefix是可选的，指定一个prefix用来获取相应的key name。如不提供并且又没有提供key name，那么组件会使用默认提供的key name。 &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;备注：&lt;/font&gt;这里所说的默认提供的key name并不是一成不变每次都是一样的，这个默认提供的key name有一个有效期，过期会变。不过这一切都不影响用户的使用，你可以将这里提到的备注忘掉。:-)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-689828889350672840?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/689828889350672840/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_24.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/689828889350672840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/689828889350672840'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility_24.html' title='Ingrian手记——CryptoUtility配置详解'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-3694139772863847463</id><published>2008-10-24T15:40:00.001+08:00</published><updated>2008-10-25T08:38:02.427+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian手记——CryptoUtility使用说明（基础）</title><content type='html'>&lt;p&gt;CryptoUtility是一个封装了Ingrian客户端组件的DLL，使.NET程序可以更方便的调用Ingrian来做加解密。下面让我们来看看如何使用这个DLL。&lt;/p&gt;  &lt;p&gt;首先我们创建一个.NET项目，是Console，是Windows或是Web的都可以，这里我们以一个Console程序为例。创建好后我们将CryptoUtility.dll这个程序集引用到我们的Console程序中来，如图：&lt;/p&gt;  &lt;p&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="166" alt="CryptoUtility_Reference" src="http://lh3.ggpht.com/sethyuan/SQF715CeFfI/AAAAAAAAA4A/zvfRryYM2HY/CryptoUtility_Reference8.gif" width="248" border="0" /&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;接下来我们来看一段代码：&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 300px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Newegg.CryptoUtility;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; CryptoUtilityDemo&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Write something:&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; something = Console.ReadLine();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (ICrypto crypto = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CryptoSession())&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;             {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; encryptedText = crypto.Encrypt(something);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                 Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Encrypted text is: {0}&amp;quot;&lt;/span&gt;, encryptedText);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; decryptedText = crypto.Decrypt(encryptedText);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;                 Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Decrypted text is: {0}&amp;quot;&lt;/span&gt;, decryptedText);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;             }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;             Console.ReadKey();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;         }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;这段代码演示的是一个很简单的场景，让用户输入一段文字，然后创建一个CryptoSession对象来加密这段文字，之后再解密加密后的文字，再将CryptoSession对象Dispose掉。正如你看到的，CryptoUtility组件的使用是非常简单的。不过光有这段代码程序还跑不起来，这是因为Ingrian需要一个帐号连接到它的服务器上，并且我们还要提供一个key name才能够进行加密或解密等操作。CryptoSession的默认构造函数会自动从App.config或Web.config中读取这些信息，所以我们可以添加一个App.config或Web.config来指定这些信息，如下：&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.userName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;sampleUser&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ingrian.password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;strike&gt;samplePassword&lt;/strike&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;appSettings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;上面配置中被划掉的部分就是连接Ingrian服务器所需的用户名和密码了，可以看到这里我们并没有指定key name，这是因为如果我们不指定的话CryptoUtility会自动帮我们找出合适的key用来加解密，这也是一般我们提倡的做法。也许你会问，&amp;#8220;那么在解密的时候CryptoUtility怎么知道我该用哪个key解密呢？&amp;#8221;，答案是CryptoUtility足够聪明，它确实能够知道该用什么key来解密，我们在使用它时就不用关心这个问题了。&lt;/p&gt;

&lt;p&gt;另外虽然没有在上面的代码片段中体现出，但是无论是在CryptoSession Open时，还是在加做解密动作时，都有可能会有异常抛出，例如连接不上Ingrian服务器就会抛出CryptoConnectionException，在加解密时出错就会抛出CryptoException等。如何根据需要在你的代码中捕获这些异常就要看你的了。下面给出一段异常处理的代码片段：&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; HandleExceptionCase()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     ICrypto crypto = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CryptoSession();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         crypto.Open();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; encryptedText = crypto.Encrypt(&lt;span style="color: #006080"&gt;&amp;quot;123&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; decryptedText = crypto.Decrypt(encryptedText);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;         &lt;span style="color: #008000"&gt;//TODO&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (CryptoConnectionException)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;         &lt;span style="color: #008000"&gt;//Handle connection problems.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (CryptoKeyException)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;         &lt;span style="color: #008000"&gt;//Handle key problems.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (CryptoException)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  23:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  24:&lt;/span&gt;         &lt;span style="color: #008000"&gt;//Handle other problems.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  26:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  27:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  28:&lt;/span&gt;         crypto.Close();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  29:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  30:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;可以看出对于CryptoSession对象的异常处理方式和SqlConnection之类的对象是一样的。也就是，平时不捕捉异常时也要养成使用C#关键字&lt;code&gt;using&lt;/code&gt;的好习惯。但如果由于性能原因需要保留CryptoSession对象的话千万别忘了在用完之后将其Close（或Dispose）掉，这一点与SqlConnection之类对象的注意事项是一样的。&lt;/p&gt;

&lt;p&gt;好了，以上就是CryptoUtility的基本使用方法，相信它已经足够应付绝大部分的应用场景了。在&lt;a href="http://world-coded.blogspot.com/2008/10/ingriancryptoutility_5534.html"&gt;高阶篇&lt;/a&gt;中我会讲到一些CryptoUtility组件的高级使用方法，当这种简单的使用方法不能满足你的需求时就可以去看看了。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-3694139772863847463?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/3694139772863847463/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/3694139772863847463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/3694139772863847463'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingriancryptoutility.html' title='Ingrian手记——CryptoUtility使用说明（基础）'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/sethyuan/SQF715CeFfI/AAAAAAAAA4A/zvfRryYM2HY/s72-c/CryptoUtility_Reference8.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-2394324773884023404</id><published>2008-10-23T17:30:00.001+08:00</published><updated>2008-10-25T08:37:00.660+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian FAQ</title><content type='html'>&lt;p&gt;我在这里汇总了一下迄今为止遇到的一些Ingrian相关的问题与解决方法，这篇博客的内容也会当有新问题时被更新。 &lt;/p&gt;  &lt;p&gt;&lt;a name="q"&gt;&lt;/a&gt;&lt;strong&gt;Questions&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000"&gt;Q1：&lt;/font&gt;&lt;a style="text-decoration: none" href="#1"&gt;使用Ingrian组件进行加解密操作时组件在建立与Ingrian Server的连接时（或之后）抛出异常。&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000"&gt;Q2：&lt;/font&gt;&lt;a style="text-decoration: none" href="#2"&gt;当我解密一个很长的字符串时会报错。&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000"&gt;Q3：&lt;/font&gt;&lt;a style="text-decoration: none" href="#3"&gt;为什么我用同一个用户和同一个key在两台机器上会得出不同的结果？&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff8000"&gt;Q4：&lt;/font&gt;&lt;a style="text-decoration: none" href="#4"&gt;为什么我昨天加密的一个字符串会和我今天加密的同一个字符串结构不一样？&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Answers&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff"&gt;&lt;a name="1"&gt;&lt;/a&gt;A1：&lt;/font&gt;这有可能是由于以下两个原因造成：&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;当前应用程序没有对Ingrian组件的读取与执行权限。请检查运行应用程序的帐户是否有对Ingrian安装目录下相应组件的读取与执行权限，包括配置文件、DLL与Windows注册表读取权限。 &lt;/li&gt;    &lt;li&gt;Ingrian配置文件中有指定输出日志，应用程序没有对此日志文件的写权限。可以先指定一个我们已知有权限的日志文件的完整路径，确认是这个问题。如是，找出日志文件的路径，给与其相应帐户的写权限。 &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;font color="#0080ff"&gt;&lt;a name="2"&gt;&lt;/a&gt;A2：&lt;/font&gt;这是Ingrian组件MSCAPI的一个限制，每次的操作都不能传递大于168,000个byte，当然这个问题和Padding也有些关系。总之在使用Ingrian组件时记住不能加解密超过167,999个byte。在String的情况下，因为字符串是以UTF8解码后得到的byte，所以一个字符串所得到的byte数要大于字符数，这点要注意。&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff"&gt;&lt;a name="3"&gt;&lt;/a&gt;A3：&lt;/font&gt;实际上你在程序中用到的并不是实际加解密用的key，而只是一个key name而已，那么这就可以解释为什么同一个用户同一个key name在两台机器上加密后的结果会不一样了。因为这两台机器很有可能连的是不同的Ingrian Server，例如GQC和生产环境的Server上的key是不一样的，虽然key name是一样的。     &lt;br /&gt;    &lt;br /&gt;这也是一个告诫，&lt;strong&gt;不要混用QGC和生产环境的数据，也就是，用GQC的key去加密生产环境数据再导到生产环境的话就会引起在生产环境下无法解密这些由GQC加密过的数据，反之亦然。&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0080ff"&gt;&lt;a name="4"&gt;&lt;/a&gt;A4：&lt;/font&gt;如果你真的运气那么好碰到了这种情况，那么只能说明时间又过了半年。O_O 我们会每半年变更一次key name（当然key也不是同一个了），所以加密的结果不一样了，不过你并不用担心，因为组件会自动找出曾经加密过它的key name，并用此去解密。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-2394324773884023404?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/2394324773884023404/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingrian-faq.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/2394324773884023404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/2394324773884023404'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingrian-faq.html' title='Ingrian FAQ'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-16162876556839867</id><published>2008-10-23T16:28:00.001+08:00</published><updated>2008-10-25T08:44:16.749+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ingrian'/><category scheme='http://www.blogger.com/atom/ns#' term='TR'/><title type='text'>Ingrian手记——安装与配置</title><content type='html'>&lt;p&gt;Ingrian是一全套企业级加解密解决方案，这个我们都知道，就不多说了。赶快来看看我们所关心的Ingrian客户端组件的安装与配置。&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;安装&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Ingrian组件的安装是非常简单的，双击随便安装在一个文件夹下即可。&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;配置&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Ingrian主要的配置文件在它的安装目录下，&lt;em&gt;IngrianNAE.properties&lt;/em&gt;，这个配置文件里有Ingrian组件所要连的Ingrian服务器的IP、端口、是否要输出日志文件，日志的输出级别等信息，里面有详细的注释解释每一个配置项。&lt;/p&gt;  &lt;p&gt;这里着重讲一下NAE_IP这个配置，这里我们指定Ingrian Server的IP，值得注意的是这里我们可以指定多个Ingrian Server的IP，当有多个以分号连接的IP时，Ingrian组件每次连接时首先会尝试第一个IP，如第一个IP连不上，那么会自动尝试第二个，以此类推，直到连上一个为止。也就是，这是Ingrian组件自己实现的一个客户端负载均衡（Client-Side Load Balancing）。另外还有一个配置项Connection_Timeout，我们建议将这个timeout设成2秒钟，这样在Load Balance的时候不至于由于第一个IP down掉了就一直等很长的时间。&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;注意：&lt;/font&gt;这个配置文件是全局的，也就是，所有在这台机器上的程序都会使用这份配置中的信息来连接Ingrian服务器，输出日志，等等。&lt;/p&gt;  &lt;p&gt;另外Ingrian会从Windows注册表中找到这个配置文件，也就是，如果在注册表中将配置文件的路径改了，那么就有可能出现找不到配置文件或配置信息错误的情况。这个键值在&amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Ingrian\NAE_Properties_Config&amp;quot;中，名字是ConfigFilename。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-16162876556839867?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/16162876556839867/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingrian.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/16162876556839867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/16162876556839867'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/ingrian.html' title='Ingrian手记——安装与配置'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-292733216495360733.post-7647087381773085448</id><published>2008-10-22T20:29:00.005+08:00</published><updated>2008-10-25T08:34:29.829+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Title'/><category scheme='http://www.blogger.com/atom/ns#' term='F#'/><title type='text'>关于我博客的Title</title><content type='html'>&lt;p&gt;看起来很奇怪的Title不是吗？可能你已经猜到了，这是某种编程语言的语法。&lt;/p&gt;  &lt;p style="font-weight: bold"&gt;F#&lt;/p&gt;  &lt;p&gt;是的，我博客的Title就是用微软研究院研发的&lt;a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx"&gt;F#&lt;/a&gt;语言描述的。F#是一个Functional Language和Object-Oriented Imperative Language的混合物，它建立在.NET CLR之上，可以与任何其他.NET平台下的语言进行互操作，是微软即将支持的有一个主流语言。&lt;/p&gt;  &lt;p style="font-weight: bold"&gt;Title表达的是什么？&lt;/p&gt;  &lt;p&gt;想了解Title表达的是什么，得先了解一点F#的语法，放心，只是一点点就足够了。首先是&amp;#8220;|&amp;gt;&amp;#8221;这个操作符，它的作用是Pipelining，也就是将左边的表达式作为参数传递给右边表达式，然后计算。其次我们要了解&amp;#8220;(属于 我)&amp;#8221;这种表达式。括号当然是为了明确标明一个个体，在这里这个个体就是一个函数&amp;#8220;属于&amp;#8221;和一个参数&amp;#8220;我&amp;#8221;的结果值。在函数式编程中一个函数的结果值（返回值）也可以是另外一个函数，函数在函数式编程中是First-Class Citizen。再次回到我们的例子中，&amp;#8220;(属于 我)&amp;#8221;会返回一个函数，而这个函数接受一个参数。&lt;/p&gt;  &lt;p&gt;完整的来看，我博客的Title便是：将&amp;#8220;代码&amp;#8221;当作参数传给&amp;#8220;创造世界&amp;#8221;这个函数，&amp;#8220;创造世界&amp;#8221;的返回值会当作参数传给&amp;#8220;(属于 我)&amp;#8221;这个函数。也就是，我博客Title的本意是：&amp;#8220;&lt;span style="font-weight: bold"&gt;用代码创造一个属于我的世界&lt;/span&gt;&amp;#8221;。&lt;/p&gt;  &lt;p&gt;以下是换做C#语法的情景：&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; 世界.创造(代码).属于(我);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;p&gt;Written by Seth Yuan&lt;/p&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/292733216495360733-7647087381773085448?l=world-coded.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://world-coded.blogspot.com/feeds/7647087381773085448/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://world-coded.blogspot.com/2008/10/title.html#comment-form' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7647087381773085448'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/292733216495360733/posts/default/7647087381773085448'/><link rel='alternate' type='text/html' href='http://world-coded.blogspot.com/2008/10/title.html' title='关于我博客的Title'/><author><name>Seth</name><uri>http://www.blogger.com/profile/10661567918743102993</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_TtUDCDHbyoo/SP3Vx6AJf8I/AAAAAAAAA1U/e4jgsoDgMGY/S220/2008051445435065.gif'/></author><thr:total>0</thr:total></entry></feed>
