<?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-5706167803821109082</id><updated>2011-11-12T21:49:01.974+01:00</updated><category term='C#'/><category term='Misc'/><category term='Visual Studio'/><category term='CSharp'/><category term='Patterns and Practices'/><category term='Security'/><category term='XSS'/><category term='SOA'/><category term='Javascript'/><category term='Tutorials'/><category term='Tips and Tricks'/><category term='WiX'/><title type='text'>Martijn's BlogSpot</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-8160541632075220719</id><published>2011-10-22T09:39:00.001+02:00</published><updated>2011-10-22T09:39:34.942+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='XSS'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Mitigating cookies theft using HttpOnly</title><content type='html'>&lt;h2&gt;Cross Side Scripting (XSS)&lt;/h2&gt;  &lt;p&gt;Cross Side Scripting is a technique that enables attackers to inject client-side script into Web pages viewed by other users. It's a computer security vulnerability typically found in Web applications. This means that a hacker would be able to insert JavaScript in a text field, say a blog post. This script would be executed by the browser, through this page, for every user that reads the post thread after it is published. The script could in turn read the current users cookie and send it to a a remote service and store is for later use.&lt;/p&gt;  &lt;p&gt;To protect a cookie against the XSS vulnerability there is a header flag available for the “Set-Cookie” HTTP response header. This header will mitigate the risk of client side script accessing the protected cookie (if the browser supports it). &lt;/p&gt;  &lt;h2&gt;Testing the theory&lt;/h2&gt;  &lt;p&gt;To test this theory, I will demonstrate it using a test application. Our test application consists of a ASP.Net web application and some javascript. The following paragraphs explain the code in detail.&lt;/p&gt;  &lt;h4&gt;Javascript&lt;/h4&gt;  &lt;p&gt;Our test javascript will retrieve the cookie collection from the response , find our specific cookie and post the value in a paragraph.&lt;/p&gt;  &lt;p&gt;The code blow shows our simple code that just reads the cookies from the response and displays it in a paragraph.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1:     &amp;lt;script type=&amp;quot;&lt;span style="color: #8b0000"&gt;text/javascript&lt;/span&gt;&amp;quot;&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3:         &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; getCookie(c_name) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4:             &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; i, x, y, ARRcookies = &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.cookie.split(&amp;quot;&lt;span style="color: #8b0000"&gt;;&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  5:             &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (i = 0; i &amp;lt; ARRcookies.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; i++) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  6:                 x = ARRcookies[i].substr(0, ARRcookies[i].indexOf(&amp;quot;&lt;span style="color: #8b0000"&gt;=&lt;/span&gt;&amp;quot;));
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  7:                 y = ARRcookies[i].substr(ARRcookies[i].indexOf(&amp;quot;&lt;span style="color: #8b0000"&gt;=&lt;/span&gt;&amp;quot;) + 1);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  8:                 x = x.replace(/^\s+|\s+$/g, &amp;quot;&lt;span style="color: #8b0000"&gt;&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  9:                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (x == c_name) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 10:                     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;unescape&lt;/span&gt;(y);
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 11:                 }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 12:             }
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 13:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 14: 
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 15:         &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; setCookieValue(c_name) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 16:             &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; username = getCookie(&amp;quot;&lt;span style="color: #8b0000"&gt;testcookie&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 17:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (username != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; username != &amp;quot;&lt;span style="color: #8b0000"&gt;&lt;/span&gt;&amp;quot;) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 18:                 &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.getElementById('pCookieValue').innerHTML = username;
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 19:             }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 20:             &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 21:                 &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.getElementById('pCookieValue').innerHTML = &amp;quot;&lt;span style="color: #8b0000"&gt;Cookie not found in request&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 22:                 }
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 23:             }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 24:     
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; 25:     &amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;h4&gt;ASP.Net application&lt;/h4&gt;

&lt;p&gt;Besides the JavaScript, the ASP.Net page contains the required HTML to display the cookie value.&lt;/p&gt;

&lt;p&gt;The code in the ASPX page, used to display the cookie value is displayed below.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt; &lt;span style="color: #ff0000"&gt;onload&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;javascript:setCookieValue('testcookie');&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;asp&lt;/span&gt;:&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Button1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Button&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;onclick&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Button1_Click&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  5:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;pCookieValue&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  6:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  7:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  8: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;h4&gt;Code behind&lt;/h4&gt;

&lt;p&gt;The code behind contains the code to set the cookie value. I use IsPostBack so we see the difference between the initial request and the refresh.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (IsPostBack)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4:     {
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  5:         var c = Response.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;testcookie&lt;/span&gt;&amp;quot;];
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  6:         c.Value = &amp;quot;&lt;span style="color: #8b0000"&gt;Testcookie Value&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  8: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now is we open the page in our browser we get the following response.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-QkgnRESRUJE/TqJzKLWx74I/AAAAAAAAAZQ/wRvyAGvvIiM/s1600-h/CookieNotFound%25255B12%25255D.png"&gt;&lt;img style="display: inline" title="CookieNotFound" alt="CookieNotFound" src="http://lh6.ggpht.com/-yAuFyUUPHrI/TqJzKVPSRaI/AAAAAAAAAZY/U70TRdpBtMs/CookieNotFound_thumb%25255B10%25255D.png?imgmax=800" width="183" height="75" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember this is the expected response, because we did not set the cookie yet. We will set it in the PostBack logic.&lt;/p&gt;

&lt;p&gt;So, after we click the “Button” button the cookie is added to the request and the value dispayed on the screen&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-kkRE1UaPNnw/TqJzKx4uqLI/AAAAAAAAAZg/vGscT9zxXwc/s1600-h/SetCookieNoHttpOnly%25255B8%25255D.png"&gt;&lt;img style="display: inline" title="SetCookieNoHttpOnly" alt="SetCookieNoHttpOnly" src="http://lh5.ggpht.com/-qSCTDtrLWVQ/TqJzLJlSJoI/AAAAAAAAAZo/eWubHq_ho0s/SetCookieNoHttpOnly_thumb%25255B6%25255D.png?imgmax=800" width="433" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-QJTcHvuZsnA/TqJzLnviAzI/AAAAAAAAAZw/LgMmmkAVikI/s1600-h/CookieFound%25255B5%25255D.png"&gt;&lt;img style="display: inline" title="CookieFound" alt="CookieFound" src="http://lh5.ggpht.com/-gEW5I3z9rlI/TqJzMLvGmYI/AAAAAAAAAZ4/rJ8Z0aVixAE/CookieFound_thumb%25255B3%25255D.png?imgmax=800" width="123" height="70" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Addind the HttpOnly&lt;/h4&gt;

&lt;p&gt;Now we add the security code to make the cookie HttpOnly. 
  &lt;br /&gt;See the OWASP resource link below for more ways to set this flag, and also in other programming languages.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (IsPostBack)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4:     {
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  5:         var c = Response.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;testcookie&lt;/span&gt;&amp;quot;];
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  6:         c.Value = &amp;quot;&lt;span style="color: #8b0000"&gt;Testcookie Value&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  7:         c.HttpOnly = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  8:     }
&lt;/pre&gt;&lt;pre style="background-color: #f1f1f8; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  9: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now when we open the page, and click the “Button” button, the cookie is set again using the HttpOnly flag. But this time the value is not displayed on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/-yXzmDd49Dis/TqJzMZ5M7FI/AAAAAAAAAaA/qt8JRiVW7TM/s1600-h/SetCookieHttpOnly%25255B7%25255D.png"&gt;&lt;img style="display: inline" title="SetCookieHttpOnly" alt="SetCookieHttpOnly" src="http://lh4.ggpht.com/-yYjEJ94x2Uw/TqJzM0BOzzI/AAAAAAAAAaI/MnbeO0_AU4E/SetCookieHttpOnly_thumb%25255B5%25255D.png?imgmax=800" width="454" height="196" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/-Inrgtljse8I/TqJzNKF4D9I/AAAAAAAAAaQ/Ue305uIDg_0/s1600-h/CookieNotFound%25255B17%25255D.png"&gt;&lt;img style="display: inline" title="CookieNotFound" alt="CookieNotFound" src="http://lh3.ggpht.com/-paVw9sCRiy0/TqJzNZyPbKI/AAAAAAAAAaY/RhUxfNc3G-E/CookieNotFound_thumb%25255B13%25255D.png?imgmax=800" width="183" height="75" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So, to conclude our findings. The &lt;strong&gt;HttpOnly&lt;/strong&gt; flag is applied to prevent a user from accessing the cookie using client side script. A sidenote, although obvious: Keep in mind that some cookie are actually used to pass state information between requests and probably need to be accessed client side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Just to clearify, this does not mean that XSS is also prevented, these two are related but not the same.&lt;/p&gt;

&lt;h2&gt;Resources&lt;/h2&gt;

&lt;p&gt;
&lt;a title="The Open Web Application Security Project (OWASP)" href="https://www.owasp.org/index.php/HttpOnly" target="_blank"&gt;The Open Web Application Security Project (OWASP)&lt;/a&gt;&lt;br/&gt;
&lt;a title="HTTP Cookies (Wikipedia)" href="http://en.wikipedia.org/wiki/HTTP_cookie" target="_blank"&gt;HTTP Cookies&lt;/a&gt;&lt;br /&gt;
&lt;a title="Cross-site scripting (Wikipedia)" href="http://en.wikipedia.org/wiki/XXS" target="_blank"&gt;Cross-site scripting&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-8160541632075220719?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/8160541632075220719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=8160541632075220719&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8160541632075220719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8160541632075220719'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2011/10/mitigating-cookies-theft-using-httponly.html' title='Mitigating cookies theft using HttpOnly'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/-yAuFyUUPHrI/TqJzKVPSRaI/AAAAAAAAAZY/U70TRdpBtMs/s72-c/CookieNotFound_thumb%25255B10%25255D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-8665198673551339068</id><published>2010-12-17T13:42:00.001+01:00</published><updated>2010-12-17T13:42:55.902+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips and Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Invert assignment direction in Visual Studio</title><content type='html'>&lt;p&gt;Ever wanted to switch the property assignments in a class, for instance in a Set_ of Get_ method.&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Internal _i = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Internal()&lt;/pre&gt;
&lt;!--CRLF--&gt;

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

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetObject(Object o)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     _i.Name = o.Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

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

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; Object GetObject()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     Object o = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Object()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     o.Name = _i.Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; o;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now, above example has only on assignment, but what if you have like 10. There is a way to do this using the build-in replace functionality.&lt;/p&gt;

&lt;p&gt;Select the lines you want to swap, Ctrl+H, then replace:&lt;/p&gt;

&lt;p&gt;Replace&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; {&lt;span style="color: #ff0000"&gt;.&lt;/span&gt;&lt;span style="color: #cc6633"&gt;*&lt;/span&gt;}:b&lt;span style="color: #cc6633"&gt;*&lt;/span&gt;=:b&lt;span style="color: #cc6633"&gt;*&lt;/span&gt;{&lt;span style="color: #ff0000"&gt;.&lt;/span&gt;&lt;span style="color: #cc6633"&gt;*&lt;/span&gt;};&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;with&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; \2 = \1;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;with [Look in:] set to [Selection].&lt;/p&gt;

&lt;p&gt;Check the [Use:] checkbox, and select [Regular expressions]&lt;/p&gt;

&lt;p&gt;Happy Coding.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-8665198673551339068?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/8665198673551339068/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=8665198673551339068&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8665198673551339068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8665198673551339068'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2010/12/invert-assignment-direction-in-visual.html' title='Invert assignment direction in Visual Studio'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-4538620458294482093</id><published>2010-06-29T15:50:00.001+02:00</published><updated>2010-06-29T15:50:06.507+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips and Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Integrating WinMerge in Visual Studio</title><content type='html'>&lt;p&gt;I've been using WinMerge for a long time now because i think it's the best, FREE, comparison and merge tool available today. What i really don't like is the comparison tool that ships with Visual Studio. &lt;/p&gt;  &lt;p&gt;For instance, the following line has a difference, but what is the difference exactly. You can figure out what it is by really staring at the line OR use WinMerge instead. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://lh3.ggpht.com/_6Oh6BEBFejw/TCn6BbSkoVI/AAAAAAAAASw/gAOjTdwyo5s/s1600-h/vs_diff5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="vs_diff" border="0" alt="vs_diff" src="http://lh6.ggpht.com/_6Oh6BEBFejw/TCn6B94dZyI/AAAAAAAAAS0/GVuUyw26DHU/vs_diff_thumb3.png?imgmax=800" width="1024" height="464" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The cool part about VS2008 is that you can configure a lot of things, and this also count for customizing tools. &lt;/p&gt;  &lt;p&gt;To intergrate WinMerge follow these simple steps. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div&gt;Go to tools -&amp;gt; options -&amp;gt; source control -&amp;gt; visual studio team foundation server -&amp;gt; &amp;quot;configure user tools&amp;quot; button. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div&gt;Click Add &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div&gt;Choose the following settings        &lt;br /&gt;        &lt;br /&gt;Extension: .*         &lt;br /&gt;Operation: Compare         &lt;br /&gt;Compare: C:\Program Files\WinMerge\WinMergeU.exe         &lt;br /&gt;Arguments: %1 %2 &lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now if you compare the files, you get the nice interface of WinMerge and can see directly what the difference in the lines is and enjoy the right features of WinMerge. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/TCn6CeQvSRI/AAAAAAAAAS4/RA3VJoUetmo/s1600-h/winmerge_diff3.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="winmerge_diff" border="0" alt="winmerge_diff" src="http://lh6.ggpht.com/_6Oh6BEBFejw/TCn6DZUfNBI/AAAAAAAAAS8/1_ryb3JKB-w/winmerge_diff_thumb1.png?imgmax=800" width="1024" height="468" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;WinMerge can be downloaded from the following &lt;a href="http://winmerge.org/" target="_blank"&gt;location&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;Enjoy. &lt;/p&gt;  &lt;p&gt;Gr.    &lt;br /&gt;Martijn.&amp;#160; &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-4538620458294482093?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/4538620458294482093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=4538620458294482093&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4538620458294482093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4538620458294482093'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2010/06/integrating-winmerge-in-visual-studio.html' title='Integrating WinMerge in Visual Studio'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_6Oh6BEBFejw/TCn6B94dZyI/AAAAAAAAAS0/GVuUyw26DHU/s72-c/vs_diff_thumb3.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-9056615379066008113</id><published>2010-06-18T10:21:00.001+02:00</published><updated>2010-06-18T10:32:25.325+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiX'/><title type='text'>Yet Another WiX Tutorial Part 3: Customizing the UI dialogs</title><content type='html'>&lt;h1&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/TBsttET4w7I/AAAAAAAAASk/a0ptrMTSpbw/s1600-h/WiX_thumb%5B9%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="WiX_thumb" border="0" alt="WiX_thumb" align="right" src="http://lh5.ggpht.com/_6Oh6BEBFejw/TBstthfzLaI/AAAAAAAAASo/g5frI0BWebU/WiX_thumb_thumb%5B7%5D.png?imgmax=800" width="107" height="79" /&gt;&lt;/a&gt; Introduction&lt;/h1&gt;  &lt;p&gt;In a &lt;a href="http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-2-my.html" target="_blank"&gt;previous post&lt;/a&gt; I showed you how to use the UIExtensions library to add predefined user interfaces to you installer. These UIExtensions are easy to use, but what if none of these suit your needs. It is possible to customize the selected UI Extension and it is quit easy to do.&lt;/p&gt;  &lt;p&gt;The following example will show you have to remove the &lt;font face="Courier New"&gt;LicenseAgreementDlg&lt;/font&gt; from the UI sequence of the &lt;font face="Courier New"&gt;WixUI_InstallDir&lt;/font&gt; extension.&lt;/p&gt;  &lt;h1&gt;Steps&lt;/h1&gt;  &lt;h3&gt;Get the source code for the UIExtension&lt;/h3&gt;  &lt;p&gt;First thing you need to do is get the sources for the version of WiX you are using. After you have downloaded them, you van browse to the UIExtension folder to get the wxs fragment file that contains the extension&lt;/p&gt;  &lt;p&gt;&amp;lt;SOURCE FOLDER&amp;gt;\src\ext\UIExtension\wixlib&lt;/p&gt;  &lt;p&gt;When you open the extension WiX file (in this case WixUI_InstallDir) you will see a fragment with the ID used by the &lt;font face="Courier New"&gt;UIRef&lt;/font&gt; node.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Wix&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://schemas.microsoft.com/wix/2006/wi&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Fragment&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UI&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_InstallDir&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The fragment contain a set of &lt;font face="Courier New"&gt;DialogRef&lt;/font&gt; nodes that refer to dialogs defined in fragment files in the same folder, and a series of &lt;font face="Courier New"&gt;Publish&lt;/font&gt; nodes, that define to order of the dialogs.&lt;/p&gt;

&lt;h3&gt;Add the fragment to you WiX script&lt;/h3&gt;

&lt;p&gt;Now select the complete UI node and add it to you WiX script.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UI&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_InstallDir&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Font_Normal&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FaceName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Tahoma&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Size&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;8&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Font_Bigger&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FaceName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Tahoma&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Size&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;12&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Font_Title&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FaceName&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Tahoma&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Size&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;9&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Bold&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;yes&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;DefaultUIFont&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Font_Normal&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Mode&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;InstallDir&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DialogRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;BrowseDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DialogRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;DiskCostDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DialogRef&lt;/span&gt; ... &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;BrowseDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;OK&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;DoAction&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUIValidatePath&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Order&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;3&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;BrowseDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;OK&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;SpawnDialog&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;InvalidDirDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Order&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;4&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;![CDATA[WIXUI_INSTALLDIR_VALID&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;1&amp;quot;]]&amp;gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; ... &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UI&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;h3&gt;Change the Dialog order&lt;/h3&gt;

&lt;p&gt;Now find the part where the LicenseAgreementDlg is Published. If you look at the dialog published before and the dialog Published after the LicenseAgreementDlg you will see that they are filling in events for two important controls, Next and Back.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WelcomeDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Next&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;NewDialog&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;LicenseAgreementDlg&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;and
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;InstallDirDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Back&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;NewDialog&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;LicenseAgreementDlg&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;To skip the &lt;font face="Courier New"&gt;LicenseAgreementDlg&lt;/font&gt;, we need to change the values of the &lt;font face="Courier New"&gt;Publish&lt;/font&gt; node to the appropriate dialog values.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WelcomeDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Next&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;NewDialog&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;InstallDirDlg&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;and
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Dialog&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;InstallDirDlg&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Control&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Back&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Event&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;NewDialog&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WelcomeDlg&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Publish&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;
Notice that we changed the values of the &lt;font face="Courier New"&gt;Publish&lt;/font&gt; node from &lt;font face="Courier New"&gt;LicenseAgreementDlg&lt;/font&gt; to the previous and next dialog ID. You can now remove the &lt;font face="Courier New"&gt;LicenseAgreementDlg&lt;/font&gt; Publish nodes if you want, or leave them to change back later. 

&lt;p&gt;Happy Coding. 
  &lt;br /&gt;Martijn.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-9056615379066008113?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/9056615379066008113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=9056615379066008113&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/9056615379066008113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/9056615379066008113'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2010/06/yet-another-wix-tutorial-part-3.html' title='Yet Another WiX Tutorial Part 3: Customizing the UI dialogs'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_6Oh6BEBFejw/TBstthfzLaI/AAAAAAAAASo/g5frI0BWebU/s72-c/WiX_thumb_thumb%5B7%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-4693181088066716345</id><published>2009-07-31T17:16:00.001+02:00</published><updated>2010-06-18T10:28:36.427+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiX'/><title type='text'>Yet Another WiX Tutorial - Index</title><content type='html'>&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_6Oh6BEBFejw/SnMJz9wYrUI/AAAAAAAAAR4/Jz7kCG1OVzw/s1600-h/WiX%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="WiX" border="0" alt="WiX" align="right" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SnMJ01hRRpI/AAAAAAAAAR8/iRopW_uGEo4/WiX_thumb%5B1%5D.png?imgmax=800" width="107" height="79" /&gt;&lt;/a&gt; I am working on new project where i am introducing the WiX Toolkit as part of our automated build process using TFSBuild. As the project evolves I am publishing my findings on this blog.&lt;/p&gt;  &lt;p&gt;The Yet Another WiX Tutorial consists of the following parts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-1.html" target="_blank"&gt;Yet Another WiX Tutorial Part 1 : An Introduction&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-2-my.html" target="_blank"&gt;Yet Another WiX Tutorial Part 2: Your First Installer&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://martijnvanschie.blogspot.com/2010/06/yet-another-wix-tutorial-part-3.html" target="_blank"&gt;Yet another WiX Tutorial Part 3: Customizing the UI dialogs&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;More to come … &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-4693181088066716345?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/4693181088066716345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=4693181088066716345&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4693181088066716345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4693181088066716345'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/07/yet-another-wix-tutorial-index_31.html' title='Yet Another WiX Tutorial - Index'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_6Oh6BEBFejw/SnMJ01hRRpI/AAAAAAAAAR8/iRopW_uGEo4/s72-c/WiX_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-2127135965942726080</id><published>2009-07-01T15:56:00.001+02:00</published><updated>2009-07-31T16:12:29.341+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Encrypted Cookies using ASP.NET</title><content type='html'>&lt;h1&gt;&lt;a href="http://lh3.ggpht.com/_6Oh6BEBFejw/SnL7ySzzH1I/AAAAAAAAAQ8/APm19U3D0sU/s1600-h/Security%20Center%5B6%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Security Center" border="0" alt="Security Center" align="right" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SnL7zN3a91I/AAAAAAAAARA/JrjgULGCJYE/Security%20Center_thumb%5B4%5D.png?imgmax=800" width="100" height="100" /&gt;&lt;/a&gt; Introduction&lt;/h1&gt;  &lt;p&gt;In order to store use specific information during a ASP.Net session you have to option to place state data in a browser &lt;a href="http://en.wikipedia.org/wiki/HTTP_cookie" target="_blank"&gt;cookie&lt;/a&gt;. These cookie are send in plain text and using various tool it is possible to read the content of these cookies. &lt;/p&gt;  &lt;p&gt;Although reading might not always be a problem, the ability to change the content of a cookie is a big thread. Tampering with the cookie is actually very easy, and i will demonstrate this using a Firefox extension called &lt;a href="http://tamperdata.mozdev.org/" target="_blank"&gt;TamperData&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;Tampering a Cookie&lt;/h1&gt;  &lt;h2&gt;Setup&lt;/h2&gt;  &lt;p&gt;I started by creating a small ASP.NET application that checks the presence of our cookie. If not sets, a cookie is create and filled in the page load. After that i print the values on the page.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;] == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:     {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:         HttpCookie cookie = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpCookie(&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:         cookie[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey&lt;/span&gt;&amp;quot;] = &amp;quot;&lt;span style="color: #8b0000"&gt;SomeValue&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:         cookie[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey&lt;/span&gt;&amp;quot;] = &amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondValue&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8:         Response.Cookies.Add(cookie);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;] != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12:     {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13:         HttpCookie cookie = Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;];
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 14:         Response.Write(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey : {0}&amp;lt;br /&amp;gt;&lt;/span&gt;&amp;quot;, cookie.Values[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey&lt;/span&gt;&amp;quot;]));
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 15:         Response.Write(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey : {0}&amp;lt;br /&amp;gt;&lt;/span&gt;&amp;quot;, cookie.Values[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey&lt;/span&gt;&amp;quot;]));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 16:     }
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 17: }&lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;Tampering with the cookie&lt;/h2&gt;

&lt;p&gt;Once we have the code ready we open the page in Firefox. Start Firefox and open TamperData. Open the page and in TamperData select the request. Because the cookie is not there yet we get a &lt;a href="http://en.wikipedia.org/wiki/List_of_HTTP_headers#Responses" target="_blank"&gt;Set-Cookie&lt;/a&gt; response header with the values.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/Sktq_fApp5I/AAAAAAAAAPM/WH3zJhSY9Xo/s1600-h/TD_SetCookie%5B13%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TD_SetCookie" border="0" alt="TD_SetCookie" src="http://lh6.ggpht.com/_6Oh6BEBFejw/SktrANwO25I/AAAAAAAAAPQ/jVGFw6q6fmc/TD_SetCookie_thumb%5B9%5D.png?imgmax=800" width="640" height="383" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The cookie values are then displayed on the page by our code.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_6Oh6BEBFejw/SktrAXYgDHI/AAAAAAAAAPU/JMaKCyuJsmo/s1600-h/cookievalues%5B12%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="cookievalues" border="0" alt="cookievalues" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SktrA57hweI/AAAAAAAAAPY/Eg4lOM418BM/cookievalues_thumb%5B10%5D.png?imgmax=800" width="507" height="234" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we can start tampering the cookie value. On the TamperData dialog click start tampering. Now refresh the page. TamperData will display a dialog asking if you want to tamper the data.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_6Oh6BEBFejw/SktrBU40EOI/AAAAAAAAAPc/-0eAhMbeF10/s1600-h/TamperRequest%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TamperRequest" border="0" alt="TamperRequest" src="http://lh3.ggpht.com/_6Oh6BEBFejw/SktrB3awTtI/AAAAAAAAAPg/IQc-W7d1YT4/TamperRequest_thumb%5B2%5D.png?imgmax=800" width="405" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now click Tamper and change the value of the cookie we are sending from SomeValue to SomeValueTampered.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SktrCVjRu9I/AAAAAAAAAPk/V1qVNH2sMas/s1600-h/TD_ChangesCookieValue%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TD_ChangesCookieValue" border="0" alt="TD_ChangesCookieValue" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SktrCzM2AOI/AAAAAAAAAPo/Ak9twysDxwE/TD_ChangesCookieValue_thumb%5B2%5D.png?imgmax=800" width="640" height="250" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;When you click OK, the request is send to the server. Inspect the new request in TamperData and see that the new values are send in the cookie.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SktrDIDiTYI/AAAAAAAAAPs/HVHBsTK5ZFY/s1600-h/TD_TamperedCookiesSend%5B6%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TD_TamperedCookiesSend" border="0" alt="TD_TamperedCookiesSend" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SktrDmMCl-I/AAAAAAAAAPw/0GC9GheI7iU/TD_TamperedCookiesSend_thumb%5B4%5D.png?imgmax=800" width="593" height="145" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The new cookie values are displayed on page.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SktrEBAkaSI/AAAAAAAAAP0/T57sBgBIeA0/s1600-h/cookievaluestampered%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="cookievaluestampered" border="0" alt="cookievaluestampered" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SktrEpuLN4I/AAAAAAAAAP4/AQ7wD-L6bNI/cookievaluestampered_thumb%5B1%5D.png?imgmax=800" width="463" height="218" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Protecting against tampering&lt;/h1&gt;

&lt;h2&gt;So what does this all mean?.&lt;/h2&gt;

&lt;p&gt;Well, as you can see, it is very easy to change the value of a cookie. Of course this is not the only way. There are multiple tools that can do this, including Fiddler.&lt;/p&gt;

&lt;p&gt;The problem here is that the server is not setting this value for fun. It will probably be using this information for the next requests. Sensitive data could be kept in this cookie. A good example would be a security token that contains you login information. If one would be able to change this data it could be a high security risk.&lt;/p&gt;

&lt;h2&gt;Encryption is the key&lt;/h2&gt;

&lt;p&gt;Now let’s demonstrate the part where we protect against tampering. We take the same solution as before, but add some encryption logic that will encrypt the cookie data using the private key of a certificate. The code used to encrypt the cookie takes a string value and a certificate. &lt;/p&gt;

&lt;p&gt;NOTE: Of course other key providers are possible to use.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; PKIEncrypt(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; data, X509Certificate2 certificate)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (certificate == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&amp;quot;&lt;span style="color: #8b0000"&gt;Certificate can not be null.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (certificate.HasPrivateKey == &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CryptographicException(&amp;quot;&lt;span style="color: #8b0000"&gt;Certificate does not contain a private key.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9:     RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PublicKey.Key;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11:     &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] plainbytes = Encoding.UTF8.GetBytes(data);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12:     &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] cipherbytes = rsa.Encrypt(plainbytes, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Convert.ToBase64String(cipherbytes);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 14: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Of course we also need to decrypt the string before we can use it in code. De decryption method takes a Base64 Encoded string and a certificate.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; PKIDecrypt(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Base64EncryptedData, X509Certificate2 certificate)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (certificate == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&amp;quot;&lt;span style="color: #8b0000"&gt;Certificate can not be null.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (certificate.HasPrivateKey == &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:         &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CryptographicException(&amp;quot;&lt;span style="color: #8b0000"&gt;Certificate does not contain a private key.&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9:     RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PrivateKey;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11:     &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] decryptedBytes = rsa.Decrypt(Convert.FromBase64String(Base64EncryptedData), &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Encoding.UTF8.GetString(decryptedBytes);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The only thing we need to do next is change the code in the Page_Load.&lt;/p&gt;

&lt;p&gt;First we get the certificate we want to use for encryption.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: X509Store store = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; X509Store(StoreName.Root, StoreLocation.LocalMachine);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: store.Open(OpenFlags.ReadOnly);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: X509Certificate2 Cert = store.Certificates.Find(
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     X509FindType.FindByThumbprint,
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     &amp;quot;&lt;span style="color: #8b0000"&gt;08 15 b7 a7 26 d3 06 0a 4f 61 b9 eb f7 e4 0f 7a 7c 24 6f 0c&lt;/span&gt;&amp;quot;,
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:     &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)[0];&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Than we add the encryption logic to the part where we assign the cookie to the request.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;] == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:     HttpCookie cookie = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpCookie(&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:     cookie[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey&lt;/span&gt;&amp;quot;] = &amp;quot;&lt;span style="color: #8b0000"&gt;SomeValue&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     cookie[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey&lt;/span&gt;&amp;quot;] = &amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondValue&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     cookie.Value = Encryption.PKIEncrypt(cookie.Value, Cert);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:     Response.Cookies.Add(cookie);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need to add the decryption logic to the part where we get and read the cookie. The reason we are making a copy of the cookie is that if if we would assign the original cookie the decrypted value, unless we encrypt it again, that would be the new value of the cookie.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;] != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:     HttpCookie cookie = Request.Cookies[&amp;quot;&lt;span style="color: #8b0000"&gt;__IGUZA.NET&lt;/span&gt;&amp;quot;];
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:     HttpCookie decryptedCookie = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HttpCookie(&amp;quot;&lt;span style="color: #8b0000"&gt;TEMP&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     decryptedCookie.Value = Decryption.PKIDecrypt(cookie.Value, Cert);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     Response.Write(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey : {0}&amp;lt;br /&amp;gt;&lt;/span&gt;&amp;quot;, decryptedCookie.Values[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeKey&lt;/span&gt;&amp;quot;]));
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:     Response.Write(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey : {0}&amp;lt;br /&amp;gt;&lt;/span&gt;&amp;quot;, decryptedCookie.Values[&amp;quot;&lt;span style="color: #8b0000"&gt;SomeSecondeKey&lt;/span&gt;&amp;quot;]));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now if we do the requests again making use of TamperData we will see a encrypted cookie value and get the following result.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SktrFEAWhsI/AAAAAAAAAP8/XC-V5Jm2GQU/s1600-h/TD_SetCookieEncrypted%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TD_SetCookieEncrypted" border="0" alt="TD_SetCookieEncrypted" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SktrFvYqYpI/AAAAAAAAAQA/gjDxEbucybY/TD_SetCookieEncrypted_thumb%5B1%5D.png?imgmax=800" width="589" height="140" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If we now start tampering and eagerly change some part of the unreadable value, we get a server error (&lt;a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error" target="_blank"&gt;500&lt;/a&gt;) because we don’t have a nice try catch logic around my code :).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_6Oh6BEBFejw/SktrGA7f99I/AAAAAAAAAQE/7_6e2OtAXsM/s1600-h/TD_EncryptedCookiesSendTampered%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TD_EncryptedCookiesSendTampered" border="0" alt="TD_EncryptedCookiesSendTampered" src="http://lh6.ggpht.com/_6Oh6BEBFejw/SktrG9XfcfI/AAAAAAAAAQI/MG6UIgkcTIQ/TD_EncryptedCookiesSendTampered_thumb%5B2%5D.png?imgmax=800" width="640" height="330" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SktrHgumxYI/AAAAAAAAAQM/QvlvtAAuIX8/s1600-h/ServerError%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ServerError" border="0" alt="ServerError" src="http://lh3.ggpht.com/_6Oh6BEBFejw/SktrIMvTrDI/AAAAAAAAAQQ/JwGsuSCn-nU/ServerError_thumb%5B1%5D.png?imgmax=800" width="644" height="178" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The only way this would work is if the person trying to change the value has the private key of the certificate used to encrypt the data. He/She would have to copy the encrypted string, decrypt it,&amp;#160; change the values, encrypt the string again and assign the encrypted value to the cookie again. The fact that the hacker would have the private key is almost unthinkable.&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Because of the fact that cookies are plain text and easy to tamper it is sometime required to protect the cookie against threads. In come cases cookies just contain unimportant data, like LastVisit, FirstName and LastName. This data could as well be send in plain text.&lt;/p&gt;

&lt;p&gt;Although it all seams easy in code, the overhead of signing and decrypting should be held against the need to protect your state data.&lt;/p&gt;

&lt;p&gt;Happy Coding.&lt;/p&gt;

&lt;p&gt;Martijn.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-2127135965942726080?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/2127135965942726080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=2127135965942726080&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/2127135965942726080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/2127135965942726080'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/07/encrypted-cookies-using-aspnet.html' title='Encrypted Cookies using ASP.NET'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_6Oh6BEBFejw/SnL7zN3a91I/AAAAAAAAARA/JrjgULGCJYE/s72-c/Security%20Center_thumb%5B4%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-3449214100071485029</id><published>2009-06-30T17:16:00.001+02:00</published><updated>2010-06-18T10:22:20.741+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiX'/><title type='text'>Yet Another WiX Tutorial Part 2: Your First Installer</title><content type='html'>&lt;h1&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SnMC02s55RI/AAAAAAAAARM/EHlyq1j7ads/s1600-h/WiX%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="WiX" border="0" alt="WiX" align="right" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SnMC1r3HbBI/AAAAAAAAARQ/hhAZdibdPAc/WiX_thumb%5B1%5D.png?imgmax=800" width="107" height="79" /&gt;&lt;/a&gt; Introduction&lt;/h1&gt;  &lt;h3&gt;What is in this tutorial&lt;/h3&gt;  &lt;p&gt;In this part of the WiX tutorial i will guide you trough your first WiX installer and explain what the important concepts are when creating a WiX file.&lt;/p&gt;  &lt;p&gt;Requirements for this part of the tutorial is that you installed the WiX toolkit as described in &lt;a href="http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-1.html" target="_blank"&gt;part 1&lt;/a&gt; of this tutorial.&lt;/p&gt;  &lt;h3&gt;Structure of a WiX script&lt;/h3&gt;  &lt;p&gt;If we look at the structure of a MSI package you will see some principles that come back in the WiX script.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SkosQUHsO9I/AAAAAAAAARU/GNzHKFoeQug/s1600-h/msi%5B1%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="msi" border="0" alt="msi" src="http://lh3.ggpht.com/_6Oh6BEBFejw/SkosRAkYVbI/AAAAAAAAARc/XA055H1_FVU/msi_thumb.png?imgmax=800" width="400" height="256" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A MSI has one or more &lt;a href="http://wix.sourceforge.net/manual-wix2/wix_xsd_feature.htm" target="_blank"&gt;features&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;A feature has one or more &lt;a href="http://wix.sourceforge.net/manual-wix2/wix_xsd_component.htm" target="_blank"&gt;components&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;A component consists of one or more items to be installed. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A component is a group of items and actions that should be installed or executed when that component is selected to be installed. The most common items would be some files and a shortcut , and an action could be to copy a file.&lt;/p&gt;  &lt;h1&gt;Creating the project&lt;/h1&gt;  &lt;h3&gt;The WiX project&lt;/h3&gt;  &lt;p&gt;We start by creating a new solution that contains a WiX project. The WiX Project template presents you with the following WiX script.&lt;/p&gt;  &lt;p&gt;For a complete &lt;a href="http://wix.sourceforge.net/manual-wix3/schema_index.htm" target="_blank"&gt;WiX schema&lt;/a&gt; I recommend going to the manual page of WiX.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;&lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Wix&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://schemas.microsoft.com/wix/2006/wi&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Product&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;e06d9811-b2f8-4e11-81fc-0e82160dae0e&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixTutorial&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Language&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1033&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:     &lt;span style="color: #ff0000"&gt;Version&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1.0.0.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Manufacturer&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;Iguza.Net&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;UpgradeCode&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;cea73ef0-4496-4da4-8608-152baf455fec&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Package&lt;/span&gt; &lt;span style="color: #ff0000"&gt;InstallerVersion&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Compressed&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;yes&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Media&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Cabinet&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;media1.cab&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EmbedCab&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;yes&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;TARGETDIR&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;SourceDir&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProgramFilesFolder&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;INSTALLLOCATION&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixTutorial&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Component&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductComponent&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Guid&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;b0789ba0-c0bb-49aa-8459-a5fac2da9cf4&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13:             &lt;span style="color: #008000"&gt;&amp;lt;!--TODO: Insert files, registry keys, and other resources here.--&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 14:           &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Component&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 15:         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 16:       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 17:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Directory&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 18: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 19:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Feature&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductFeature&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Title&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixTutorial ConsoleApp&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Level&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 20:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ComponentRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductComponent&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 21:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Feature&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 22:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Product&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 23: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Wix&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;So what do we see here?.&lt;/p&gt;

&lt;p&gt;We start out with a product node, which specifies the properties of out installer.&lt;/p&gt;

&lt;p&gt;We skip the &lt;font face="Courier New"&gt;&amp;lt;Media&amp;gt;&lt;/font&gt; node for now. Second thing we see is a directory structure using &lt;font face="Courier New"&gt;&amp;lt;Direcory&amp;gt;&lt;/font&gt; nodes which defines the installation folder structure. Within this directory structure we insert &lt;font face="cou"&gt;&lt;font face="Courier New"&gt;&amp;lt;component&amp;gt;&lt;/font&gt; &lt;/font&gt;element in the location where the components should be installed. In our example we will be adding some files that need to be installed.&lt;/p&gt;

&lt;h3&gt;Adding Files&lt;/h3&gt;

&lt;p&gt;I started by adding a new console application project names “WixTutorial.ConsoleApp” and implement some simple code in the mail method.&lt;/p&gt;

&lt;p&gt;To add this file to the installer add a &lt;font face="Courier New"&gt;&amp;lt;File&amp;gt;&lt;/font&gt; node in the component. Every item should have a unique ID. The WiX compiler will actually warn you about this beforehand.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Component&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductComponent&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Guid&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;b0789ba0-c0bb-49aa-8459-a5fac2da9cf4&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;File&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;FILE_CONSOLEAPP&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixTutorial.ConsoleApp.exe&amp;quot;&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:         &lt;span style="color: #ff0000"&gt;DiskId&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;$(var.ConsoleFolder)\WixTutorial.ConsoleApp.exe&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Component&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;First we introduce a variable called $(var.ConsoleFolder). This will make the script more flexible because we can set the value, for instance during a build process. You could provide this variable as a command line parameter but for now we fill it hard coded. To do this, add the following snippet right after the &lt;font face="Courier New"&gt;&amp;lt;Wix&amp;gt;&lt;/font&gt; node and replace the &lt;font face="Courier New"&gt;&amp;lt;%FOLDER LOCATION%&amp;gt;&lt;/font&gt; placeholder with the root folder of your console build folder.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;define ConsoleFolder = &amp;quot;&amp;lt;%FOLDER LOCATION%&amp;gt;&amp;quot; &lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;We should now be able to build the project. After the build has finished we end up with a MSI file in the output folder of the WiX project.&lt;/p&gt;

&lt;p&gt;Running this MSI will finish quickly and it will look like it didn’t do much. But is we look in the install folder “c:\program files\WixTutorial” we will actually see our file. Also, using the “Add/Remove Programs” console, we are able to uninstall the application. The reason for this is that our installer does not contain any definition for installation dialogs and simply installs without user interaction.&lt;/p&gt;

&lt;h3&gt;Adding Interfaces&lt;/h3&gt;

&lt;p&gt;To include some user interface we can use one of the precompiled UI sequences that come with the toolkit. For a list of these templates i refer you to a very good article at &lt;a href="http://www.tramontana.co.hu/wix/lesson2.php#2.3" target="_blank"&gt;WiX tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To get started we need to first add a reference to the UI extensions library to our WiX project using the well know “Add Reference” dialog.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SnMC2hTkbYI/AAAAAAAAARg/Fg4AZrzy9EM/s1600-h/AddUIExtensions4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AddUIExtensions" border="0" alt="AddUIExtensions" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SnMC3UqLg5I/AAAAAAAAARk/mtfxEav7uxk/AddUIExtensions_thumb2.jpg?imgmax=800" width="399" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select the WixUIExtention.dll, click add and then OK.&lt;/p&gt;

&lt;p&gt;After this reference has been set, we add the most complete user interface to the WiX script. So add the following as a child of the &lt;font face="Courier New"&gt;&amp;lt;Product&amp;gt;&lt;/font&gt; node.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UIRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixUI_Mondo&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Using this one line of code,&amp;#160; the following main dialogs are included: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=PrepareDlg"&gt;PrepareDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=WelcomeDlg"&gt;WelcomeDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=SetupTypeDlg"&gt;SetupTypeDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=CustomizeDlg"&gt;CustomizeDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=VerifyReadyDlg"&gt;VerifyReadyDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=ProgressDlg"&gt;ProgressDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=MaintenanceWelcomeDlg"&gt;MaintenanceWelcomeDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=MaintenanceTypeDlg"&gt;MaintenanceTypeDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=ResumeDlg"&gt;ResumeDlg&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following dialogs are also included: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=ErrorDlg"&gt;ErrorDlg&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=FatalError"&gt;FatalError&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=FilesInUse"&gt;FilesInUse&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=MsiRMFilesInUse"&gt;MsiRMFilesInUse&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=UserExit"&gt;UserExit&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.wixwiki.com/index.php?title=ExitDialog"&gt;ExitDialog&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it, we are done.&lt;/p&gt;

&lt;p&gt;Now if we repeat the installation we should see actual screens. One of these would be the “Setup Type” selection dialog and when choosing “Custom” the feature selection dialog pops up.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SnMC3w3X0iI/AAAAAAAAARo/6HxvhXCyQCY/s1600-h/CustomSetupDialog2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomSetupDialog" border="0" alt="CustomSetupDialog" src="http://lh4.ggpht.com/_6Oh6BEBFejw/SnMC4VpvAsI/AAAAAAAAARs/aOU5bA8MYKc/CustomSetupDialog_thumb.jpg?imgmax=800" width="541" height="428" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;Some Final Tweaks&lt;/h3&gt;

&lt;p&gt;This is all pretty neat, but why can’t we set the installation folder?. We need to add one more attribute to our selected feature node.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Feature&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductFeature&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Title&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;WixTutorial ConsoleApp&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Level&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2:          &lt;span style="color: #ff0000"&gt;ConfigurableDirectory&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;INSTALLLOCATION&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ComponentRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;ProductComponent&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Feature&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The ConfigurableDirectory attribute is set to the folder id that we are allowed to change during the installation. If we run the MSI again after the build, we can select the installation folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SnMC40ax15I/AAAAAAAAARw/bzMrtP4K_NM/s1600-h/CustomSetupDialogFolderSelect3.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomSetupDialogFolderSelect" border="0" alt="CustomSetupDialogFolderSelect" src="http://lh3.ggpht.com/_6Oh6BEBFejw/SnMC5flCaAI/AAAAAAAAAR0/00LVw_iG7Ok/CustomSetupDialogFolderSelect_thumb1.jpg?imgmax=800" width="467" height="207" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;What’s in the next part&lt;/h1&gt;

&lt;p&gt;That’s it. Our first simple installer is finished. Take a look at the actual XML that was needed and you will see that it’s very straight foreword and easy to read.&lt;/p&gt;

&lt;p&gt;The next tutorial will go deeper into tweaking the WiX script and working with variables during a build.&lt;/p&gt;

&lt;p&gt;Happy Coding.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-3449214100071485029?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/3449214100071485029/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=3449214100071485029&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/3449214100071485029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/3449214100071485029'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-2-my.html' title='Yet Another WiX Tutorial Part 2: Your First Installer'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_6Oh6BEBFejw/SnMC1r3HbBI/AAAAAAAAARQ/hhAZdibdPAc/s72-c/WiX_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-8227876617833188463</id><published>2009-06-16T15:55:00.001+02:00</published><updated>2009-08-26T08:55:26.060+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Patterns and Practices'/><title type='text'>A List Of Microsoft Patterns And Practices Documents</title><content type='html'>&lt;h1&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" border="0" align="right" src="http://i.msdn.microsoft.com/bb190332.wwheadline(en-us,MSDN.10).jpg" /&gt; Patterns &amp;amp; Practices&lt;/h1&gt;  &lt;p&gt;I have put together an interesting list of all Patterns and Practices books available on the internet that i could find. Most of the have some relation to development. If you know some that are missing, please let me know.&lt;/p&gt;  &lt;h2&gt;Architecture&lt;/h2&gt;  &lt;p&gt;Application Architecture for .NET: Designing Applications and Services    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms954595.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A08E4A09-7AE3-4942-B466-CC778A3BAB34&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Application Architecture Guide 2.0    &lt;br /&gt;&lt;a href="http://www.codeplex.com/AppArchGuide" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.codeplex.com/AppArchGuide/Release/ProjectReleases.aspx?ReleaseId=20586" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enterprise Solution Patterns Using Microsoft .NET    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998469.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=3C81C38E-ABFC-484F-A076-CF99B3485754&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Development&lt;/h2&gt;  &lt;p&gt;.NET Data Access Architecture Guide    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms978510.aspx" target="_blank"&gt;HTML&lt;/a&gt; – &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0D95803A-59D7-46E2-8DFA-01905846AC67&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Exception Management in .NET    &lt;br /&gt;HTML | PDF&lt;/p&gt;  &lt;p&gt;Improving .NET Application Performance and Scalability    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998530.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=8A2E454D-F30E-4E72-B531-75384A0F1C47&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Security&lt;/h2&gt;  &lt;p&gt;Improving Web Service Security Guide    &lt;br /&gt;HTML | &lt;a href="http://www.codeplex.com/WCFSecurityGuide/Release/ProjectReleases.aspx?ReleaseId=15892" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Building Secure ASP.NET Applications    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa302415.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=055ff772-97fe-41b8-a58c-bf9c6593f25e&amp;amp;DisplayLang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Web Service Security    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa480545.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=3E02A6C8-128A-47C2-9F39-4082582F3FE1&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Security Engineering Explained    &lt;br /&gt;HTML | &lt;a href="http://www.microsoft.com/downloads/thankyou.aspx?familyId=75039f39-b33a-4bbd-b041-cf25f7473a0b&amp;amp;displayLang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Improving Web Application Security: Threats and Countermeasures   &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms994921.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E9C4BFAA-AF88-4AA5-88D4-0DEA898C31B9&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication   &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa302415.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=055ff772-97fe-41b8-a58c-bf9c6593f25e&amp;amp;DisplayLang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Other&lt;/h2&gt;  &lt;p&gt;Building Interoperable Web Services    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms953977.aspx" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=60080CA9-2466-43E4-A19C-8A9DE724ABA8&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Team Development with Visual Studio Team Foundation Server    &lt;br /&gt;&lt;a href="http://www.codeplex.com/TFSGuide" target="_blank"&gt;HTML&lt;/a&gt; | &lt;a href="http://www.codeplex.com/TFSGuide/Release/ProjectReleases.aspx?ReleaseId=6280" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Upgrading Visual Basic 6.0 Applications to Visual Basic .NET and Visual Basic 2005    &lt;br /&gt;HTML | &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=7C3FE0A9-CBED-485F-BFD5-847FB68F785D&amp;amp;displaylang=en" target="_blank"&gt;PDF&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-8227876617833188463?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/8227876617833188463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=8227876617833188463&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8227876617833188463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/8227876617833188463'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/06/list-of-microsoft-patterns-and.html' title='A List Of Microsoft Patterns And Practices Documents'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-2689162010648421807</id><published>2009-06-14T17:21:00.001+02:00</published><updated>2009-07-12T19:08:30.589+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='SOA'/><category scheme='http://www.blogger.com/atom/ns#' term='CSharp'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Reliable Message Exchange Using XML Signing</title><content type='html'>&lt;h1&gt;&lt;a href="http://lh6.ggpht.com/_6Oh6BEBFejw/SloYiy1guGI/AAAAAAAAAQs/3lwwbOTyplU/s1600-h/Security%20Center%5B3%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="Security Center" border="0" alt="Security Center" align="right" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SloYjQKhmMI/AAAAAAAAAQw/JCQAOA9sqaQ/Security%20Center_thumb%5B1%5D.png?imgmax=800" width="100" height="100" /&gt;&lt;/a&gt; Introduction&lt;/h1&gt;  &lt;p&gt;A well known service oriented scenario is where a client and service application communicate using message exchange over a channel. This channel is either secured, using for instance SSL, or unsecured where the data is send in plain text.&lt;/p&gt;  &lt;p&gt;One of the commonly used message bases is XML. XML is a standard way of describing relational data, and can be read by most platforms. This makes XML a interoperable message base.&lt;/p&gt;  &lt;p&gt;On the downside, this message type is easy to read and it therefore easy to change. If a third party where to intercept the message, for instance using a proxy server, it could easily change the content of the message and send it to the original endpoint. This is called tampering.&lt;/p&gt;  &lt;p&gt;To detect changes to the content, a message send through the channel can be signed. Signing is a way to provide reliable messaging over a non-secure channel. It also provides some sort of authentication because the message can be validate that is was send from the expected client.&lt;/p&gt;  &lt;h1&gt;Principle of signing&lt;/h1&gt;  &lt;p&gt;A digital signature on a message is like a footprint of that message. Before the message is send, the hash is calculated and encrypted using a key. This key can be a custom key, a fixed key from a key store, or the key from a certificate. On the receiving endpoint, the supplied signature can be validates against the newly calculated value. In any scenario, the sender and receiver should share some sort of key infrastructure to sing and validate the messages.&lt;/p&gt;  &lt;p&gt;The following image gives a overview of the signing and validation of a message using the private and public key of a shared certificate.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_6Oh6BEBFejw/SjaN-PamHBI/AAAAAAAAAO8/mLihaZSooyA/s1600-h/Security%20-%20Signing%5B14%5D.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Security - Signing" border="0" alt="Security - Signing" src="http://lh6.ggpht.com/_6Oh6BEBFejw/SjaN-lFN9SI/AAAAAAAAAPA/6zzUokEO2Yc/Security%20-%20Signing_thumb%5B8%5D.png?imgmax=800" width="644" height="181" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So let’s put this theory to practice using the .NET Framework&lt;/p&gt;  &lt;h1&gt;Signing using the .NET Framework&lt;/h1&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;The Setup&lt;/h2&gt;  &lt;p&gt;To get started, i have a small XML file representing the message to be transferred over the channel. Nothing fancy, just to show what the results will be. &lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; &lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Person&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Firstname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;John&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Firstname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Lastname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Doe&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Lastname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Person&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Second, i have imported a certificate into the certificate store. The certificate contains a private and public key and will be used for signing and verification purpose. Normally you would use a certificate with private key on the sending endpoint and import the same certificate on the receiving side containing only the public key.&lt;/p&gt;

&lt;p&gt;To demonstrate the signing and validation, I'll guide you trough the code required using a console application. Of course in a OOAD pattern, this logic could be in a separate logic library like a utilities library.&lt;/p&gt;

&lt;p&gt;Disclaimer: 
  &lt;br /&gt;I did not take all the time to insert nice error handing code so don’t comment me on that. Always implement good exception handling.&lt;/p&gt;

&lt;h2&gt;Retrieving the certificate&lt;/h2&gt;

&lt;p&gt;I’m retrieving the certificate from the certificate store using the unique thumbprint. The .NET library has evolved nicely in the part, because it now supports a easy way to do this exact thing.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: X509Store store = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; X509Store(StoreName.My, StoreLocation.LocalMachine);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: store.Open(OpenFlags.ReadOnly);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: X509Certificate2 Cert = store.Certificates.Find(
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     X509FindType.FindByThumbprint,
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:     &amp;quot;&lt;span style="color: #8b0000"&gt;e5 d9 de 0f ed 08 34 09 c2 83 0f f2 11 4a e9 a0 b0 7b 86 9f&lt;/span&gt;&amp;quot;,
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:     &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)[0];
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9: &lt;span style="color: #008000"&gt;// Generate a signing key.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: RSACryptoServiceProvider privateKey = Cert.PrivateKey &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; RSACryptoServiceProvider;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The false bool in the Find method indicated if i only want to use valid certificates. As this is not important in the example i set this to false.&lt;/p&gt;

&lt;h2&gt;Signing&lt;/h2&gt;

&lt;p&gt;To sign the XML file, i created a method that takes the filename of the original message, the name of the resulting message, and the key to use for the signing.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Will sign the XML file using the key proivided and saves it.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: SignXmlFile(&amp;quot;&lt;span style="color: #8b0000"&gt;MySecureDocument.xml&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;MySecureDocument-Signed.xml&lt;/span&gt;&amp;quot;, privateKey);&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The first thing we will do is read the XML file into a XmlDocument and create a SignedXml object referencing the message. We then set the key to the SigningKey property.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Create a new XML document.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: XmlDocument doc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDocument();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #008000"&gt;// Load the passed XML file using its name.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: doc.Load(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlTextReader(FileName));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7: &lt;span style="color: #008000"&gt;// Create a SignedXml object.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: SignedXml signedXml = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SignedXml(doc);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: &lt;span style="color: #008000"&gt;// Add the key to the SignedXml document. &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11: signedXml.SigningKey = Key;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The SignedXml object is kind of a misleading name, as it does not contain the signed XML but only the signature informational part. In my opinion, a more logical name would be XmlSignature. The SignedXml will be added to the XML message later.&lt;/p&gt;

&lt;p&gt;Next, we need to add a Reference object to the SignedXml object. This tells the signing algorithm what part of the message to use to calculate the signature. It also contains a signature transform property that described the way the signature is provided.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Create a reference to be signed.  Pass &amp;quot;&amp;quot; &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: &lt;span style="color: #008000"&gt;// to specify that all of the current XML&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: &lt;span style="color: #008000"&gt;// document should be signed.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: Reference reference = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Reference();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: reference.Uri = &amp;quot;&lt;span style="color: #8b0000"&gt;&lt;/span&gt;&amp;quot;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7: &lt;span style="color: #008000"&gt;// Add an enveloped transformation to the reference.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: XmlDsigEnvelopedSignatureTransform env = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDsigEnvelopedSignatureTransform();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9: reference.AddTransform(env);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11: &lt;span style="color: #008000"&gt;// Add the reference to the SignedXml object.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12: signedXml.AddReference(reference);&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;After the signing algorithm is setup we can start calculating the signature and assign it to the XML message. I say we as in code. .NET Framework does all the calculating for us.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Compute the signature.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: signedXml.ComputeSignature();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #008000"&gt;// Get the XML representation of the signature and save&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: &lt;span style="color: #008000"&gt;// it to an XmlElement object.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: XmlElement xmlDigitalSignature = signedXml.GetXml();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: &lt;span style="color: #008000"&gt;// Append the element to the XML document.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9: doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11: &lt;span style="color: #008000"&gt;// Save the signed XML document&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12: XmlTextWriter xmltw = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlTextWriter(SignedFileName, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UTF8Encoding(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;));
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13: doc.WriteTo(xmltw);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 14: xmltw.Close();&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The resulting XML file will contain a additional Signature node containing all the information to be validated.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Person&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Firstname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;John&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Firstname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Lastname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Doe&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Lastname&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Signature&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://www.w3.org/2000/09/xmldsig#&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SignedInfo&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CanonicalizationMethod&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Algorithm&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://www.w3.org/TR/2001/REC-xml-c14n-20010315&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SignatureMethod&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Algorithm&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://www.w3.org/2000/09/xmldsig#rsa-sha1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Reference&lt;/span&gt; &lt;span style="color: #ff0000"&gt;URI&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Transforms&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 10:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Transform&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Algorithm&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://www.w3.org/2000/09/xmldsig#enveloped-signature&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 11:         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Transforms&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 12:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DigestMethod&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Algorithm&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;http://www.w3.org/2000/09/xmldsig#sha1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 13:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DigestValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;haEx+J1wgjeVDYyfdqNr2vdJypE=&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DigestValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 14:       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Reference&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 15:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SignedInfo&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 16:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SignatureValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;PXh7px6IXOVh0ilFbIKhVqBupNIP3He...&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SignatureValue&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 17:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Signature&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt; 18: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Person&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;Validation&lt;/h2&gt;

&lt;p&gt;Validation is more straight forward. As described in the introduction in our example we validate the signature using the public key of the shared certificate. We can retrieve this again from the certificate store.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// This time we use the public key&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: RSACryptoServiceProvider publicKey = Cert.PublicKey.Key &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; RSACryptoServiceProvider;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;After this we simulate receiving the message by reading the signed file from disk and assigning it to the SignedXml object.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Create a new XML document.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: XmlDocument xmlDocument = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDocument();
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #008000"&gt;// Load the passed XML file into the document. &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: xmlDocument.Load(Name);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7: &lt;span style="color: #008000"&gt;// Create a new SignedXml object and pass it&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: &lt;span style="color: #008000"&gt;// the XML document class.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  9: SignedXml signedXml = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SignedXml(xmlDocument);&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we get the signature node and validate the signature.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  1: &lt;span style="color: #008000"&gt;// Find the &amp;quot;Signature&amp;quot; node and create a newXmlNodeList object.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  2: XmlNodeList nodeList = xmlDocument.GetElementsByTagName(&amp;quot;&lt;span style="color: #8b0000"&gt;Signature&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  4: &lt;span style="color: #008000"&gt;// Load the signature node.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  5: signedXml.LoadXml((XmlElement)nodeList[0]);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #eaeaff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  7: &lt;span style="color: #008000"&gt;// Check the signature and return the result.&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 11px"&gt;  8: &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; signedXml.CheckSignature(Key);&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And that’s it. Your all done. The bool will tell you if the signature was OK.&lt;/p&gt;

&lt;h1&gt;Summary&lt;/h1&gt;

&lt;p&gt;To prevent tampering of data, non-repudiation and to provide extra authentication it is possible to sign your messages. Of course this involves some extra overhead and loss of performance, depending on the size of the document and to overcome this, hardware signing is a possibility.&lt;/p&gt;

&lt;p&gt;Keep in mind that you are still sending readable, none encrypted data over the channel if you are not using SSL so it will not prevent someone else from reading it until you do.&lt;/p&gt;

&lt;p&gt;Hope you enjoyed this post.&lt;/p&gt;

&lt;p&gt;Regards, 
  &lt;br /&gt;Martijn.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-2689162010648421807?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/2689162010648421807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=2689162010648421807&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/2689162010648421807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/2689162010648421807'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/06/reliable-message-exchange-using-xml.html' title='Reliable Message Exchange Using XML Signing'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_6Oh6BEBFejw/SloYjQKhmMI/AAAAAAAAAQw/JCQAOA9sqaQ/s72-c/Security%20Center_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-4396254165679662834</id><published>2009-06-12T11:06:00.001+02:00</published><updated>2009-07-31T16:14:50.990+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiX'/><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><title type='text'>Yet Another WiX Tutorial Part 1 : An Introduction</title><content type='html'>&lt;h1&gt;&lt;a href="http://lh5.ggpht.com/_6Oh6BEBFejw/SnL8WD2S6rI/AAAAAAAAARE/4cKHysWQfUA/s1600-h/WiX%5B3%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="WiX" border="0" alt="WiX" align="right" src="http://lh5.ggpht.com/_6Oh6BEBFejw/SnL8WoA0MQI/AAAAAAAAARI/eZvHSthRwLw/WiX_thumb%5B1%5D.png?imgmax=800" width="107" height="79" /&gt;&lt;/a&gt; WiX in a nutshell&lt;/h1&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Quote:&lt;/h2&gt;  &lt;blockquote&gt;   &lt;p&gt;The Windows Installer XML (WiX) is a toolset that builds Windows installation packages from XML source code. The toolset supports a command line environment that developers may integrate into their build processes to build MSI and MSM setup packages.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I could not have said it better myself.&lt;/p&gt;  &lt;h2&gt;The main components&lt;/h2&gt;  &lt;p&gt;The three mains components I use from the toolkit are the following.    &lt;br /&gt;(Although i found another useful one called heat.exe that I'll explain in a later tutorial)&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;candle.exe : used to compile a WiX file &lt;/li&gt;    &lt;li&gt;light.exe : used to create the MSI from the compiled file &lt;/li&gt;    &lt;li&gt;dark.exe : used to decompile a MSI into a WiX script &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_6Oh6BEBFejw/SjIaok-LF7I/AAAAAAAAAOk/yLQJYb2Gxoc/s1600-h/wix%20components%5B24%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="wix components" border="0" alt="wix components" src="http://lh6.ggpht.com/_6Oh6BEBFejw/SjIapX52PhI/AAAAAAAAAOo/2NGb60GQB3Y/wix%20components_thumb%5B20%5D.jpg?imgmax=800" width="260" height="186" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h1&gt;The usage of WiX&lt;/h1&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;In one of the projects I'm working on we use Windows Installer XML (or WiX) to create a setup package during the automated build process. Although we have the build process under control, and we have a generic way of integrating WiX in our build process i wanted to know more about WiX, and see if i could optimize it.&lt;/p&gt;  &lt;p&gt;The way the the initial WiX script was created is by taking a working MSI package, that contains a custom installer class, and decompile it to a WiX script. Cleaning it up and adding the appropriate settings (like product name and version) and than create some project specific settings we supply to the WiX compiler using parameters to build the MSI.&lt;/p&gt;  &lt;p&gt;Why go trough all this trouble you might ask. Visual studio has a nice setup project template that build using MSBuild as well. Of course that’s true, but it is limited in what it can do. At least we found ourselves writing a lot of logic in a custom installer class, and adding that to the project. Another small detail was updating the version number of the setup during build.&lt;/p&gt;  &lt;p&gt;As i found out later, some of this logic was actually supported by WiX and made it all easier as well. That’s why I've put all my findings together and started created this step by step tutorial series.&lt;/p&gt;  &lt;h2&gt;An example&lt;/h2&gt;  &lt;p&gt;We use custom code to install a virtual directory under IIS and map it to the web application that comes with the installation.&amp;#160; This can actually be done using simple WiX code … and … it’s transactional. No custom rollback or uninstall code.&lt;/p&gt;  &lt;p&gt;Another thing we do is that we pack our web applications in a ZIP archive, and add this to the installer. Using the custom installer, we unzip it. This also means that we have to write uninstall logic, as de MSI only knows about the zip file included. I looked into a better solution and found a more generic way to include all the files from a web application, or build output folder, and include the file in the installer. With this solution you are skipping the rollback and uninstall logic, unzipping and install folder cleaning.&lt;/p&gt;  &lt;p&gt;Last interesting thing was windows services. We now install them using a custom action. This means that again we have to write rollback logic and uninstall logic. This was error prone because if the service was still running it can’t be deleted.&lt;/p&gt;  &lt;h2&gt;Conclusion.&lt;/h2&gt;  &lt;p&gt;Although WiX has a slight learning curve, in the end a good WiX script leave a lot of installation, rollback and uninstall logic to the windows installation process leaving more time to write only the pre installation logic, like configuration dialogs, in the custom installers (although this can also be done using WiX).&lt;/p&gt;  &lt;h1&gt;The WiX Toolkit&lt;/h1&gt;  &lt;h2&gt;Getting the toolkit&lt;/h2&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Installation is a piece of cake. Download the latest “RC” version from the &lt;a href="http://sourceforge.net/projects/wix" target="_blank"&gt;SourceForge.Net&lt;/a&gt; page. During the course of these tutorials I will be using version 3.0.5217.0.&lt;/p&gt;  &lt;h2&gt;installation&lt;/h2&gt;  &lt;p&gt;With the installation you get the complete command line toolset. Besides that &lt;a href="http://wix.sourceforge.net/votive.html" target="_blank"&gt;Votive&lt;/a&gt; is installed. This is the visual studio package. It add a new project type to visual studio, including 5 new project templates. I will come back to this in a next tutorial.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_6Oh6BEBFejw/SjIaqMhYjOI/AAAAAAAAAOs/qjMSdhFluNY/s1600-h/wix%20vs2008%20template%5B9%5D.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="wix vs2008 template" border="0" alt="wix vs2008 template" src="http://lh6.ggpht.com/_6Oh6BEBFejw/SjIarPDnkpI/AAAAAAAAAOw/oJVv-6twQfU/wix%20vs2008%20template_thumb%5B7%5D.png?imgmax=800" width="640" height="327" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;A final suggestion&lt;/h2&gt;  &lt;p&gt;I recommend adding the installation path of the toolkit (default: “C:\Program Files\Windows Installer XML v3\bin”) of WiX to your environmental variables, so you don’t have to type the whole path every time you run a script from the command line.&lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;What’s in the next part&lt;/h1&gt;  &lt;p&gt;In the next part of the tutorial I will guide you trough creating a basic installation from scratch, using the WiX project template in visual studio.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-4396254165679662834?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/4396254165679662834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=4396254165679662834&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4396254165679662834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/4396254165679662834'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/06/yet-another-wix-tutorial-part-1.html' title='Yet Another WiX Tutorial Part 1 : An Introduction'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_6Oh6BEBFejw/SnL8WoA0MQI/AAAAAAAAARI/eZvHSthRwLw/s72-c/WiX_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5706167803821109082.post-224155646923761487</id><published>2009-06-11T22:16:00.001+02:00</published><updated>2009-06-12T08:15:04.152+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Misc'/><title type='text'>Welcome to my blog</title><content type='html'>&lt;p&gt;Hi, and welcome to my blog.&lt;/p&gt;  &lt;p&gt;I started this blog because i find myself surfing the net for new stuff and never have take the time to keep track of everything. Most of the time i collect info from different resources and in the end lose track of it.&lt;/p&gt;  &lt;p&gt;This blog will be my repository for my findings, and should be a resource for later.&lt;/p&gt;  &lt;p&gt;I will start with a set of tutorials about WiX.&lt;/p&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;  &lt;p&gt;Gr.   &lt;br /&gt;Martijn.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5706167803821109082-224155646923761487?l=martijnvanschie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://martijnvanschie.blogspot.com/feeds/224155646923761487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5706167803821109082&amp;postID=224155646923761487&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/224155646923761487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5706167803821109082/posts/default/224155646923761487'/><link rel='alternate' type='text/html' href='http://martijnvanschie.blogspot.com/2009/06/welcome-to-my-blog.html' title='Welcome to my blog'/><author><name>Martijn van Schie</name><uri>http://www.blogger.com/profile/06940648243792921003</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-pBUGnzO-v8Q/TrLjbBnc4dI/AAAAAAAAAas/1yZ-Y_hizs8/s220/IMG_2693.JPG'/></author><thr:total>0</thr:total></entry></feed>
