<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Connected Information Security Group</title><link>http://blogs.msdn.com/b/cisg/</link><description /><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>This Blog URL Has Changed – Please Update Your Readers</title><link>http://blogs.msdn.com/b/cisg/archive/2009/04/16/this-blog-url-has-changed-please-update-your-readers.aspx</link><pubDate>Thu, 16 Apr 2009 17:52:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9552998</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9552998</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/04/16/this-blog-url-has-changed-please-update-your-readers.aspx#comments</comments><description>&lt;p&gt;Things have been quite on the blog for while. There is a LOT of code being cranked out at the moment as we work towards some deadlines in the summer on various projects. &lt;/p&gt;  &lt;p&gt;Our team name has also changed from the Connected Information Security Group (CISG) to the Microsoft IT Information Security Tools Team. This reflects an increased scope of tools that we are building and areas that we are focusing on so we have updated the blog URL. Well leave all the content as is on this blog but all new content will be posted at the new URL. &lt;/p&gt;  &lt;p&gt;As well as news about significant work on CAT.NET and a Beta for TAM 3.0 we plan to start sharing details of the development framework CISF that we are building and a Risk Tracker application; both of which we plan to release open source under an MS-PL license this summer. CISF is a set of reusable components and code from which you can assemble your own security management applications (including gluing various security tools and technology together). It’s built in C# and on the MSFT technology stack (.NET 3.5 (WWF, WCF. ASP.NET etc)), SQL Server 2008 and Windows Server. You can think of Risk Tracker as a “Security Starter Kit” using the CISF; it’s essentially a Risk Tracking application that we have built internally for the corporate information security team which we will generalize and share with the community. You will be able to run it as is or extend it with .NET and the CISF. We plan to extend both tools on a regular basis (quarterly updates) as we improve the tools and technology for internal use. &lt;/p&gt;  &lt;p&gt;More news in a few weeks!&lt;/p&gt;  &lt;p&gt;You can subscribe to the new blog at &lt;a href="http://blogs.msdn.com/securitytools"&gt;http://blogs.msdn.com/securitytools&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Cheers!&lt;/p&gt;  &lt;p&gt;Mark&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9552998" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Frameworks+and+Platforms/">Frameworks and Platforms</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Product+Management/">Product Management</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/BPM/">BPM</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>CAT.NET New Build – 1.1.1.8</title><link>http://blogs.msdn.com/b/cisg/archive/2009/03/20/cat-net-new-build-1-1-1-8.aspx</link><pubDate>Fri, 20 Mar 2009 22:02:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9493214</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9493214</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/03/20/cat-net-new-build-1-1-1-8.aspx#comments</comments><description>&lt;p&gt;Mainly small bug fixes and a new feature to export the findings into an Excel spreadsheet. &lt;/p&gt;  &lt;p&gt;Download link is -&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We recommend all users to upgrade to this version. &lt;/p&gt;  &lt;p&gt;We have some work now starting on new features including general performance improvements, UI improvements and rules maintenance. We expect these to be complete by summer after which time we then expect to undertake some core engine updates to significantly improve the performance, scalability and vulnerability coverage. &lt;/p&gt;  &lt;p&gt;Note: The MSDN download page says 1.0 but it is 1.1.1.8. well fix that ;-)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9493214" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Getting Help for CAT.NET and Anti-XSS</title><link>http://blogs.msdn.com/b/cisg/archive/2009/02/23/getting-help-for-cat-net-and-anti-xss.aspx</link><pubDate>Mon, 23 Feb 2009 17:42:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9441385</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9441385</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/02/23/getting-help-for-cat-net-and-anti-xss.aspx#comments</comments><description>&lt;p&gt;We now have a discussion forum for users of CAT.NET. There is no official support for these tools but you can ask questions and we will try to help wherever we can!&lt;/p&gt;  &lt;p&gt;CAT.NET - &lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/catnet/threads/"&gt;http://social.msdn.microsoft.com/Forums/en-US/catnet/threads/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Anti-XSS - &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.codeplex.com/AntiXSS/Thread/List.aspx"&gt;http://www.codeplex.com/AntiXSS/Thread/List.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9441385" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>MSDN Webcast: Software Security with Static Code Analysis Using CAT.NET (Level 200)</title><link>http://blogs.msdn.com/b/cisg/archive/2009/02/16/msdn-webcast-software-security-with-static-code-analysis-using-cat-net-level-200.aspx</link><pubDate>Tue, 17 Feb 2009 02:32:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9426708</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9426708</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/02/16/msdn-webcast-software-security-with-static-code-analysis-using-cat-net-level-200.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Event Overview&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In this webcast, we provide an overview of what static code analysis is and typical coding errors that static analysis can and cannot detect. We also look at the recently released CAT.NET tool and how it helps with the detection of security flaws.    &lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Presenter: &lt;/b&gt;Andreas Fuchsberger, Senior Software Design Engineer, Microsoft Corporation&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msevents.microsoft.com/CUI/Register.aspx?culture=en-US&amp;amp;EventID=1032402660&amp;amp;CountryCode=US"&gt;Register Here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9426708" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>AntiXSS Library V3.0 - Test Harness</title><link>http://blogs.msdn.com/b/cisg/archive/2009/01/19/antixss-library-v3-0-test-harness.aspx</link><pubDate>Mon, 19 Jan 2009 13:55:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9339842</guid><dc:creator>cisg</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9339842</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/01/19/antixss-library-v3-0-test-harness.aspx#comments</comments><description>&lt;p&gt;Hi, Anil Chintala here&amp;#8230;&lt;/p&gt;  &lt;p&gt;In this post I wanted to talk about the new Test Harness application which was released as part of the AntiXSS V3.0 Beta and is available as a free &lt;a target="_blank" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;amp;displaylang=en"&gt;download on MSDN&lt;/a&gt; with source code available for &lt;a target="_blank" href="http://www.codeplex.com/AntiXSS/"&gt;download on CodePlex&lt;/a&gt;. Test Harness application is created to help the users to quickly get started and validate the successful blocking of XSS issues by the Library and also to measure the enhanced performance claims of the AntiXSS V 3.0 against Microsoft .NET encoding library.&lt;/p&gt;  &lt;p&gt;AntiXSS Test Harness is a windows console application that automates the following two categories of tests - XSS validation and performance tests. When executed, AntiXSS Test Harness displays this console menu:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image002_thumb.jpg" width="327" height="167" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Performance Test Bench&lt;/b&gt; uses HtmlEncode() method as a benchmark for measuring performance of the AntiXSS library - AntiXss.HtmlEncoding(&amp;#8230;) method against the .NET - HttpUtility.HtmlEncode(&amp;#8230;) encoding method. Input strings with a combination of safe and un-safe characters are used as payload to run the automated performance tests. &lt;/p&gt;  &lt;p&gt;Choosing Option#1, Performance Test Bench executes performance tests that analyze such metrics as: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Input string lengths&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Encoded output strings&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;and the total time taken for its execution.&amp;#160; &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;During its run, Performance Test Bench compares the execution times of .NET's HttpUtility.HtmlEncode and AntiXss.HtmlEncode and stores in an output file containing results as displayed in this illustration: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image004_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image004_thumb.jpg" width="322" height="228" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;XSS Validation Test Bench&lt;/b&gt; demonstrates the successful blocking of cross-site scripts. These tests use a list of XSS exploits as payload for running the automated tests. XSS exploit list are read from a text file, each payload is run through HTMLEncode() method of the library and the encoded output is stored in an output file.&lt;/p&gt;  &lt;p&gt;When Option 2 is selected from the above console screen, Test Harness application executes the XSS validation tests and produces the following output file:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image006_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clip_image006" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/AntiXSSV3.0TestHarness_1404C/clip_image006_thumb.jpg" width="324" height="228" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Test Harness Application provides a framework for automating the XSS validation and performance evaluation. Primary objective is to help developers and testers to quickly get started and test AntiXSS library for XSS validation and performance. With the availability of source code on CodePlex it also allows advanced users to extend the automated testing capabilities as per your specific requirements.&lt;/p&gt;  &lt;p&gt;Thanks and more later&amp;#8230;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9339842" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category></item><item><title>Current Memory Limitations of CAT.NET</title><link>http://blogs.msdn.com/b/cisg/archive/2009/01/12/current-memory-limitations-of-cat-net.aspx</link><pubDate>Mon, 12 Jan 2009 15:19:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9307697</guid><dc:creator>cisg</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9307697</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/01/12/current-memory-limitations-of-cat-net.aspx#comments</comments><description>&lt;p&gt;Hi, Andreas Fuchsberger here.....&lt;/p&gt;  &lt;p&gt;It is important to understand what happens CAT.NET builds its Call Flow Super Graphs. We use a CCI object called CciControlGraph to build a Control Flow Graph for each method and each method call we find in the Common Intermediate Language (CIL) of the modules being analysed. These individual control flow graphs are collected together in a .NET List object.&lt;/p&gt;  &lt;p&gt;Unfortunately this is where we start to encounter a shortcoming in the implementation. Even with virtual memory there are limits to how much memory a single .NET application can allocate. As reported &lt;a href="http://blogs.msdn.com/tom/archive/2008/04/10/chat-question-memory-limits-for-32-bit-and-64-bit-processes.aspx"&gt;in recent blog post&lt;/a&gt; a 32-bit process, such as the CAT.NET Visual Studio plug-in version can only allocate about 1200 MB, even on a 4GB RAM (32-bit) system. Moreover another shortcoming of the current implementation is that when CAT.NET runs out of memory is it exits with an unhandled OutOfMemory (OOM) exception, unfortunately this does not get reported by the Visual Studio plug-in and the plug-in just seems to hang.&lt;/p&gt;  &lt;p&gt;There is a solution, on the same 4 GB RAM system you can more than double the amount of memory available to CAT.NET by using a 64-bit version of Vista or Windows Server and the 64-bit command line version of CAT.NET. This is why we supply the 64-bit command line version of the CAT.NET binaries: (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e0052bba-2d50-4214-b65b-37e5ef44f146"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=e0052bba-2d50-4214-b65b-37e5ef44f146&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;For those without the option of running on a 64-bit system, one manual method for analysing larger applications that the 32-bit version of CAT.NET fails to do is to restrict the number of modules that are passed to CAT.NET. For a developer analysing their own code it is relatively easy to make sensible choices which modules should be analysed together. Typically they would choose all the their own as code that receives user input and any dependant modules, e.g. third party libraries, that process that input to produce an output, leaving all other business logic modules aside. However it must be pointed out that this method lead to some vulnerabilities being missed.&lt;/p&gt;  &lt;p&gt;We are working on scalable long term solutions to these sorts of problems which require some relatively heavy lifting on our part. For today hopefully the above advice will at least help understand why the issue happens. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9307697" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Free MSDN Webcast: Managing Cross-Site Scripting Using CAT.NET and AntiXSS (Level 200)</title><link>http://blogs.msdn.com/b/cisg/archive/2009/01/04/free-msdn-webcast-managing-cross-site-scripting-using-cat-net-and-antixss-level-200.aspx</link><pubDate>Sun, 04 Jan 2009 12:36:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9271114</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9271114</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/01/04/free-msdn-webcast-managing-cross-site-scripting-using-cat-net-and-antixss-level-200.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Language(s):&lt;/strong&gt;    &lt;br /&gt;English.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Product(s):&lt;/strong&gt;    &lt;br /&gt;Security.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Audience(s): &lt;/strong&gt;    &lt;br /&gt;Developer.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Duration:&lt;/b&gt;    &lt;br /&gt;60 Minutes&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Start Date:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Friday, January 09, 2009 12:00 PM Pacific Time (US &amp;amp; Canada)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032398771&amp;amp;EventCategory=4&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;Register Here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9271114" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Merlin: Better Specifications for CAT.NET</title><link>http://blogs.msdn.com/b/cisg/archive/2009/01/02/merlin-better-specifications-for-cat-net.aspx</link><pubDate>Fri, 02 Jan 2009 22:05:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9269576</guid><dc:creator>cisg</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9269576</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2009/01/02/merlin-better-specifications-for-cat-net.aspx#comments</comments><description>&lt;p&gt;Guest post by &lt;a href="http://research.microsoft.com/en-us/um/people/livshits/"&gt;Ben Livshits&lt;/a&gt; of Microsoft Research here....&lt;/p&gt;  &lt;p&gt;In the last several years we have seen a proliferation of static (and sometimes runtime) analysis tools for finding web application vulnerabilities. Companies such as Fortify, Ouncelabs, Klockwork, and others have been selling tools for finding security flaws for a while now. Most focus of the &lt;a href="http://www.owasp.org/index.php/Top_10_2007"&gt;OWASP top 10&lt;/a&gt;, a list being dominated by XSS, SQL injection, CSRF, etc. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cisg/archive/2008/12/18/cat-net-ctp-links-are-live-again.aspx"&gt;CAT.NET&lt;/a&gt; is a state-of-the-art static analysis tool for .NET that we have built at Microsoft and released for free to all of our customers. &lt;/p&gt;  &lt;p&gt;The &lt;em&gt;effectiveness&lt;/em&gt; of these tools is generally seen as a function of false positives and false negatives. Ideally, of course, you want to find all real vulnerabilities &lt;em&gt;and &lt;/em&gt;eliminate&amp;#160; all false alarms. In practice, most tools have to cut corners to avoid erring too much in either direction. While much has been said about the approaches to static analysis and improving result quality, an Achilles heel of any analysis tool is the quality of the &lt;em&gt;specification&lt;/em&gt; that comes with. Simply, the analysis engine needs to be told what to look for. If the tool doesn&amp;#8217;t know what methods are used for sending queries to a database and are therefore crucial to SQL injection finding or if some taint sources are omitted for XSS, some potential vulnerabilities will go missing. The following is but a short list of taint sources in typical .NET APIs:&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="400" align="center"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;ul&gt;           &lt;ul&gt;             &lt;li&gt;Request.Params &lt;/li&gt;              &lt;li&gt;Request.QueryString &lt;/li&gt;              &lt;li&gt;Request.Form &lt;/li&gt;              &lt;li&gt;Request.Headers &lt;/li&gt;           &lt;/ul&gt;         &lt;/ul&gt;       &lt;/td&gt;        &lt;td valign="top" width="200"&gt;         &lt;ul&gt;           &lt;ul&gt;             &lt;li&gt;Request.ServerVariables &lt;/li&gt;              &lt;li&gt;Request.Cookies &lt;/li&gt;              &lt;li&gt;TextBox.Text &lt;/li&gt;              &lt;li&gt;HiddenField.Value &lt;/li&gt;           &lt;/ul&gt;         &lt;/ul&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;However, as a &lt;a href="http://blogs.msdn.com/cisg/archive/2008/09/10/real-world-xss-vulnerabilities-in-asp-net-code.aspx"&gt;recent blog&lt;/a&gt; post discusses, this list is woefully incomplete. Even in the case of taint-style vulnerabilities, coming up with a complete specification is really hard for several reasons. First, it often requires pouring over tons of potentially relevant APIs. There are about 30 methods in .NET base class libraries alone that CAT.NET considers to be taint sources. Second, in many cases, the specification is application- or library-specific. For a large-scale app, it&amp;#8217;s not uncommon to have a custom encoder or a sanitizer. Unless the tool knows about it, false positives will likely result.&lt;/p&gt;  &lt;p&gt;Enter Merlin, an add-on for CAT.NET that aims to produce a better, more complete and accurate specification for finding security bugs. Merlin uses the intuition embedded within the application itself to infer a better specification. &lt;/p&gt;  &lt;h3&gt;Code Example&lt;/h3&gt;  &lt;p&gt;Consider a simple example below. Suppose we are trying to classify functions &lt;strong&gt;ReadData1&lt;/strong&gt;, &lt;strong&gt;ReadData2&lt;/strong&gt;, &lt;strong&gt;WriteData&lt;/strong&gt;, and &lt;strong&gt;Cleanse&lt;/strong&gt; as either &lt;em&gt;sources&lt;/em&gt;, &lt;em&gt;sanitizers&lt;/em&gt;, or &lt;em&gt;sinks&lt;/em&gt;. Unless we know something else about these example, this is hard to do. &lt;/p&gt;  &lt;table border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="614"&gt;         &lt;div style="border-bottom: gray 1px solid; border-left: gray 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px"&gt;           &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;             &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ProcessRequest()&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; s1 = &lt;strong&gt;ReadData1&lt;/strong&gt;(&lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; s2 = &lt;strong&gt;ReadData2&lt;/strong&gt;(&lt;span style="color: #006080"&gt;&amp;quot;encoding&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; s3 = &lt;strong&gt;Cleanse&lt;/strong&gt;(s1);&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;    WriteData(&lt;span style="color: #006080"&gt;&amp;quot;Parameter &amp;quot;&lt;/span&gt; + s1);&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;    WriteData(&lt;span style="color: #006080"&gt;&amp;quot;Header &amp;quot;&lt;/span&gt; + s2);&lt;/pre&gt;

            &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="318"&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/MerlinbetterspecficationsforCAT.NET_1474F/image_2.gif" rel="WLPP"&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="image" border="0" alt="image" align="right" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/MerlinbetterspecficationsforCAT.NET_1474F/image_thumb.gif" width="282" height="303" /&gt;&lt;/a&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;However, if you are told that &lt;strong&gt;ReadData1&lt;/strong&gt; and &lt;strong&gt;ReadData2&lt;/strong&gt; are &lt;em&gt;sources &lt;/em&gt;and &lt;strong&gt;Cleanse&lt;/strong&gt; is a &lt;em&gt;sanitizer, &lt;/em&gt;then &lt;strong&gt;WriteData&lt;/strong&gt; is likely to be is a sink. Why? Because why else would the developer sanitize tainted input on not one, but two paths. This is most obvious if you look at the propagation graph on the right.&lt;/p&gt;

&lt;p&gt;In other words, the program itself contains valuable clues that tell us what the developer &lt;em&gt;thought&lt;/em&gt; these functions were with respect to tainting or untaining values. Of course, the developer could still be wrong, there would be no vulnerabilities otherwise, so Merlin generally looks for preponderance of evidence before drawing any conclusions. In this case, Merlin will be able to classify &lt;strong&gt;WriteData&lt;/strong&gt; as a sink with a pretty high probability. The technique that Merlin uses called statistical inference is a generalization of the intuition above.&lt;/p&gt;

&lt;h3&gt;What does Merlin give us: some results&lt;/h3&gt;

&lt;p&gt;Before we talk about the gory technical details, which are also described in great detail in &lt;a href="http://research.microsoft.com/en-us/um/people/livshits/papers/tr/merlin_tr.pdf"&gt;our technical report&lt;/a&gt;, I&amp;#8217;ll give you a glimpse of what our approach can do by citing some experimental results. What is utterly surprising is that, without requiring &lt;em&gt;any initial specification at all&lt;/em&gt;, Merlin is able to derive the following specification shown on the right from the little program below.&lt;/p&gt;

&lt;div style="border-bottom: gray 1px solid; border-left: gray 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px"&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TextChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e) {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str = Request.QueryString[&lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;];&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str2 = HttpUtility.HtmlEncode(str);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     Response.Write(str2);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ButtonClicked(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e) {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str = Request.UrlReferrer.AbsolutePath;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str2 = HttpUtility.UrlEncode(str);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     Response.Redirect(str2);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Here is what Merlin infers for this example program:&lt;/p&gt;

&lt;div style="border-bottom: lightgray 1px solid; border-left: lightgray 1px solid; padding-bottom: 5px; margin: 10px; padding-left: 5px; padding-right: 5px; border-top: lightgray 1px solid; border-right: lightgray 1px solid; padding-top: 5px"&gt;&lt;strong&gt;Sources (1):&lt;/strong&gt; 

  &lt;br /&gt;string System.Web.HttpUtility+UrlDecoder.Getstring() 

  &lt;br /&gt;&lt;strong&gt;Sanitizers (8): 
    &lt;br /&gt;&lt;/strong&gt;string &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httputility.htmlencode.aspx "&gt;System.Web.HttpUtility.HtmlEncode&lt;/a&gt;(string) 

  &lt;br /&gt;string System.Web.HttpUtility.UrlEncodeSpaces(string) 

  &lt;br /&gt;string &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urldecode.aspx "&gt;System.Web.HttpServerUtility.UrlDecode&lt;/a&gt;(string) 

  &lt;br /&gt;string &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx "&gt;System.Web.HttpUtility.UrlEncode&lt;/a&gt;(string, Encoding) 

  &lt;br /&gt;string &lt;a href="msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx "&gt;System.Web.HttpUtility.UrlEncode&lt;/a&gt;(string) 

  &lt;br /&gt;string System.Web.HttpServerUtility.UrlEncode(string) 

  &lt;br /&gt;string System.Web.HttpUtility.UrlDecodestringFromstringInternal... 

  &lt;br /&gt;string System.Web.HttpUtility.UrlDecode(string, Encoding) 

  &lt;br /&gt;&lt;strong&gt;Sinks (4):&lt;/strong&gt; 

  &lt;br /&gt;void System.Web.HttpResponse.WriteFile(string) 

  &lt;br /&gt;void System.Web.HttpRequest.set_QuerystringText(string) 

  &lt;br /&gt;void System.IO.TextWriter.Write(string) 

  &lt;br /&gt;void System.Web.HttpResponse.Redirect(string)&lt;/div&gt;

&lt;p&gt;This is actually a pretty good start! I highlighted a few of the methods so that you can look up their definition at MSDN. The sanitizers are in fact standard URL and HTML encoders provided by .NET. Note that even some of these are missing from the default .NET specification. You will recognize some other methods like HttpResponse.Redirect as sinks for the reflective XSS vulnerability. Similarly, HttpResponse.WriteFile exposes a command injection vulnerability.&lt;/p&gt;

&lt;p&gt;Of course, the better your initial specification, the more Merlin can help. The second part of this blog will talk about the technical aspects of Merlin inference and also show some more results.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3ebc6f03-0ae7-4a33-95f9-559fb87891d0" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/CAT.NET" rel="tag"&gt;CAT.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/static%20analysis" rel="tag"&gt;static analysis&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;More reading: &lt;a href="http://research.microsoft.com/en-us/um/people/livshits/papers/tr/merlin_tr.pdf"&gt;Merlin technical report&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9269576" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Security Code Review Using CAT.NET - Part 2</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/22/security-code-review-using-cat-net-part-2.aspx</link><pubDate>Mon, 22 Dec 2008 12:24:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9246695</guid><dc:creator>cisg</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9246695</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/22/security-code-review-using-cat-net-part-2.aspx#comments</comments><description>&lt;p&gt;Hi Andreas Fuchsberger here again......&lt;/p&gt;  &lt;p&gt;How does CAT.NET work?&lt;/p&gt;  &lt;p&gt;As I mentioned in &lt;a href="http://blogs.msdn.com/cisg/archive/2008/12/22/security-code-review-using-cat-net-part-1.aspx"&gt;Part 1 here&lt;/a&gt;, CAT.NET is an information-flow type static analysis tool using an implementation of tainted-variable analysis. &lt;/p&gt;  &lt;p&gt;Tainted-variable analysis is an integrity problem in which that tries to identify whether less-trusted data obtained from the user might influence other data that the system trusts. Clearly, to do this analysis, sources and sinks of possibly tainted data need to be identified. For managed code, this amounts to identifying methods that originate a tainted value and methods that use a possibly tainted value. For CAT.NET a number of XML of user editable configuration files is used to define sources and sinks. Then CAT.NET needs to find how information is stored in a variable and where it is used later in any other module of the application.&lt;/p&gt;  &lt;p&gt;CAT.NET uses the Common Compiler Infrastructure (CCI) which is used extensively within Microsoft for building compiler-like tools.CCI is an integrated set of components that encapsulate the logic that compilers and related development tools typically have in common. CCI has many features but firstly for CAT.NET it has the ability to read the Common Intermediate Language (CIL) used to store binary code in a .NET Framework assembly directly. &lt;/p&gt;  &lt;p&gt;Further to perform its analysis CAT.NET needs to build of a specific heap analysis called flow-insensitive &lt;i&gt;points-to&lt;/i&gt; analysis. This analysis computes a &amp;#8220;may point to&amp;#8221; relation over a loaded assembly or assemblies, we&amp;#8217;ll call this relation &lt;i&gt;pointsTo, &lt;/i&gt;where &lt;i&gt;pointsTo(o&lt;sub&gt;1&lt;/sub&gt;.f, o&lt;sub&gt;2&lt;/sub&gt;)&lt;/i&gt; means that the field &lt;i&gt;f&lt;/i&gt; of the object named &lt;i&gt;o&lt;sub&gt;1&lt;/sub&gt;&lt;/i&gt; might refer to the object named &lt;i&gt;o&lt;sub&gt;2&lt;/sub&gt;&lt;/i&gt; in some execution of the program. A may-point-to relation is also computed for local variables: &lt;i&gt;pointsTo(&amp;#965;, o)&lt;/i&gt; means that the local variable &lt;i&gt;&amp;#965;&lt;/i&gt; might refer to the object named &lt;i&gt;o&lt;/i&gt;. The relation &lt;i&gt;pointsTo(&amp;#965;.f, o)&lt;/i&gt; holds if there exists an &lt;i&gt;o&amp;#8217;&lt;/i&gt; such that &lt;i&gt;pointsTo(&amp;#965;, o&amp;#8217;)&lt;/i&gt; and &lt;i&gt;pointsTo(o&amp;#8217;.f, o)&lt;/i&gt;.&lt;/p&gt;  &lt;p&gt;CAT.NET uses a combination of Control Flow and Data Flow Graphs and to build the relation for every object in every module supplied to CAT.NET. &lt;/p&gt;  &lt;p&gt;Control Flow Graphs&lt;/p&gt;  &lt;p&gt;A control flow graph (CFG) is a representation of a program where contiguous regions of code without branches, known as basic blocks, are represented as nodes in a graph and edges between nodes indicate the possible flow of the program. A CFG shows the sequence of events as a program executes. &lt;/p&gt;  &lt;p&gt;Data Flow Graphs&lt;/p&gt;  &lt;p&gt;A data-flow graph (DFG) is a graph which represents operations and data dependencies and the order the operations are performed. As such any algorithm consists of a number of ordered operations. However simple DFGs are not able to represent loops or sub routine branching. Data Flow Graphs are therefore are often augmented with control-flow information and are then known as Control Data Flow Graphs (CDFG). A DFG consists of nodes and arcs, where the each node represented has an input or an output port and an arc represents a connection between and input and output port. &lt;/p&gt;  &lt;p&gt;Data Flow Super Graphs&lt;/p&gt;  &lt;p&gt;Defined by CAT.NET a data flow super graph is a special type of data flow graph that contains data flow information at both an intra-procedural and inter-procedural level.&lt;/p&gt;  &lt;p&gt;CCI provides functions for building the Data Flow and Control Flow Graphs on an intra-procedural level and CAT.NET uses these to build a Data Flow Super Graph. The Data Flow Super Graph that CAT.NET builds covers all objects across methods in all modules on an inter-procedural level.&lt;/p&gt;  &lt;p&gt;Once the Data Flow Super Graph is built, CAT.NET iterates for each of the XML that makes up the CAT.NET rules across Data Flow Super Graph to find all data flow paths between the sources and the sinks. It does this by traversing each path in the Data Flow Super Graph and colouring (i.e. assigning a constant to a traversed path) the graph according to the variables use. &lt;/p&gt;  &lt;p&gt;Before reporting a source is linked to a sink, CAT.NET checks how the variable is transformed and filters out valid transformations. Variables that remain tainted once a complete source to sink path has been traversed are reported as a possible vulnerability in the original code including file name and line numbers.&lt;/p&gt;  &lt;p&gt;In the next post I will explain the semantics of the XML rules and how to modify the supplied rule set.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9246695" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Security Code Review Using CAT.NET - Part 1</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/22/security-code-review-using-cat-net-part-1.aspx</link><pubDate>Mon, 22 Dec 2008 12:20:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9246683</guid><dc:creator>cisg</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9246683</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/22/security-code-review-using-cat-net-part-1.aspx#comments</comments><description>&lt;p&gt;Hi Andreas Fuchsberger here &amp;#8230;&lt;/p&gt;  &lt;p&gt;To coincide with the &lt;a href="http://blogs.msdn.com/cisg/archive/2008/12/15/anti-xss-3-0-beta-and-cat-net-community-technology-preview-now-live.aspx"&gt;CTP release of CAT.NET and Anti-XSS&lt;/a&gt;, within the &lt;a href="http://blogs.msdn.com/cisg/archive/2008/08/25/test.aspx"&gt;CSIG&lt;/a&gt; we have been taking a long hard look at static analysis tools for developers and Information Security professionals. Over the next series of blog posts I will explain the fundamentals of the techniques used for a code review in general and static code analysis in particular. &lt;/p&gt;  &lt;p&gt;Today we start with an introduction into the review process and as well having a look at the techniques for automating some of the code review burden; and don't worry we will build up to the details fast. &lt;/p&gt;  &lt;p&gt;In general we differentiate between a code review (source code) and an architectural review (software architecture). Although CAT.NET actually reads binary, actually Microsoft Intermediate Language code, it falls into the class of source code review tools.&lt;/p&gt;  &lt;p&gt;What is a code review?&lt;/p&gt;  &lt;p&gt;We say a code review is the process of systematically examining the source code written by one developer by someone other than the original developer, often called a reviewer. The reviewer could be a colleague or fellow developer or someone with similar developer background and skill set then we refer to this as a peer-review. Although most developers see the purpose of a code review to find coding errors the true value really lies really in the reviewer questioning assumptions by the original developer. It is often these unconsciously made assumptions that are the cause of business logic errors but also simple security errors (&amp;#8220;Oh the user would never try to enter more than 10 digit telephone number&amp;#8221;) .&lt;/p&gt;  &lt;p&gt;Formal roots of the code review go as far back as 1983 when it was first mentioned in a standard, IEEE 729, although it is probably true to say that code reviews took place before using corporate or in-house rules. &lt;/p&gt;  &lt;p&gt;According to the IEEE standard 729 &amp;#8220;Glossary of Software Engineering Terminology&amp;#8221;, which has since been republished as IEEE 610.12, a review is formally planned and structured analysis and evaluation process, during which the project results are presented to a team of consultant reviewers and commentated or approved by them.&lt;/p&gt;  &lt;p&gt;The reviewer could be a fellow software developer. For inexperienced developers a code review offers a good opportunity to learn, for an experienced developer it offers the opportunity for training themselves in fast and hands-on manner.&lt;/p&gt;  &lt;p&gt;And this unfortunately this is why the review process is so expensive both in cost of time and money. Reviewers are highly skilled people and performing a review takes time. So for some time now the Information Security research community has proposed automatic analysis techniques for identifying security vulnerabilities in code. Such techniques may employ dynamic analysis, static analysis, or both. &lt;/p&gt;  &lt;p&gt;Dynamic analysis entails executing the program and inferring properties from its observed behaviour. Although dynamic analysis may expose bugs, it cannot ensure complete coverage of the target program as not all program paths may be actually run.&lt;/p&gt;  &lt;p&gt;Instead, developers have adopted an approach based on sound analysis, which can provably identify all possible violations of specific security guidelines.&lt;/p&gt;  &lt;p&gt;In contrast Static analysis does not execute the code but analyses the code itself. Simple static analysis tools analyses the actual source code, however increasingly modern static analysis tools use also or only look at the binary output of the compiler. For intermediate code output, such as Microsoft&amp;#8217;s .NET Framework, this is in fact often preferable as the intermediate output still contains type information and &lt;/p&gt;  &lt;p&gt;Static analysis techniques&lt;/p&gt;  &lt;p&gt;There exist a number of static analysis techniques that can be used to automatically detect security errors in source code. These techniques cover three areas that have been associated with sources of security vulnerabilities:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Access control &lt;/li&gt;    &lt;li&gt;Information flow      &lt;ul&gt;       &lt;li&gt;Integrity violations &lt;/li&gt;        &lt;li&gt;Confidentiality violations &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;API conformance &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Access control: Mechanisms for access control restrict access to security-sensitive resources based on a user's identity and/or membership in predefined groups. Ensuring that an access control policy enforces the required level of security can be difficult, especially for systems with many components of different trust levels with access to a multitude of restricted resources. If an access control policy does not grant sufficient permissions to users, runtime authorization failures will occur. On the other hand, if an access control policy grants users unnecessary permissions, this will result in exposing the exposing the system to security attacks.&lt;/p&gt;  &lt;p&gt;Information flow: A secure information flow ensures that information propagates throughout the execution environment without violating two security integrity properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Integrity violations arise when untrusted information flows into a trusted execution environment without having been properly validated. A malicious user could compromise a system by exploiting an integrity violation. &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;li&gt;Confidentiality violations arise when confidential information flows from a restricted execution environment to a public one without having been properly declassified. For example, a confidentiality violation arises if trusted code exposes a cryptographic private key to untrusted code. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;API conformance: Applications often rely on libraries and third-party APIs to provide security-sensitive services. As an example, many applications rely heavily on cryptography libraries to protect confidentiality, prevent integrity violations, and distinguish between trusted and untrusted entities. Incorrect usage of cryptographic functions may lead to insecure storage of security-sensitive information and cause violations of integrity and confidentiality policies.&lt;/p&gt;  &lt;p&gt;Our CAT.NET tool is based on finding integrity violations by performing a tainted data flow analysis. Future posting will take a closer look at the algorithms we used for performing our analysis.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9246683" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>CAT.NET CTP Links Are Live Again!</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/18/cat-net-ctp-links-are-live-again.aspx</link><pubDate>Thu, 18 Dec 2008 03:37:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9232985</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9232985</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/18/cat-net-ctp-links-are-live-again.aspx#comments</comments><description>&lt;p&gt;Download CAT.NET CTP (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en"&gt;32 bit here&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=e0052bba-2d50-4214-b65b-37e5ef44f146&amp;amp;displaylang=en"&gt;64 bit here&lt;/a&gt;) &lt;/p&gt;  &lt;p&gt;Anti-XSS was not affected but for completeness&lt;/p&gt;  &lt;p&gt;Download Anti-XSS 3.0 Beta (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;amp;displaylang=en"&gt;here&lt;/a&gt; and &lt;a href="http://www.codeplex.com/AntiXSS/"&gt;source code here&lt;/a&gt;)&lt;/p&gt;  &lt;p&gt;Our sincere apologies.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9232985" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>CAT.NET Status Update</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/17/cat-net-status-update.aspx</link><pubDate>Wed, 17 Dec 2008 23:05:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9231528</guid><dc:creator>cisg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9231528</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/17/cat-net-status-update.aspx#comments</comments><description>&lt;p&gt;12 pm PST 17th, December.&lt;/p&gt;  &lt;p&gt;We continue to face issues with the download links. We are doing everything we can to resolve this and expect it to be resolved within a few hours. &lt;/p&gt;  &lt;p&gt;We will update this blog with any further news. &lt;/p&gt;  &lt;p&gt;Our sincere apologies. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9231528" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Secure String in .Net - Part II</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/17/secure-string-in-net-part-ii.aspx</link><pubDate>Wed, 17 Dec 2008 15:59:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9225667</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9225667</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/17/secure-string-in-net-part-ii.aspx#comments</comments><description>&lt;p&gt;Hi Gaurav Sharma here with more information about SecureStrings. This time I'll cover following topics:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;SecureString internals&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let us start with our first topic,&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;u&gt;SECURE STRING INTERNALS&lt;/u&gt;&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;&lt;strong&gt;BASICS&lt;/strong&gt;           &lt;ul&gt;           &lt;li&gt;Class Name: &lt;em&gt;SecureString&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Assembly: &lt;em&gt;mscorlib.dll&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Latest Version: &lt;em&gt;2.0.0.0&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Namespace: &lt;em&gt;System.Security&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Implements: &lt;em&gt;IDisposable&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Inherits: &lt;em&gt;CriticalFinalizerObject&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Access Specifier: &lt;em&gt;Public&lt;/em&gt; &lt;/li&gt;            &lt;li&gt;Can be inherited: &lt;em&gt;No, it is a sealed class               &lt;br /&gt;&lt;/em&gt;&lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;&lt;strong&gt;INTERNALS&lt;/strong&gt;           &lt;ul&gt;           &lt;li&gt;&lt;strong&gt;Constructors&lt;/strong&gt; - SecureString type contains four constructor implementations out of which one is a type constructor and other three are instance constructors.               &lt;ul&gt;               &lt;li&gt;&lt;strong&gt;static SecureString()&lt;/strong&gt;                   &lt;ul&gt;                   &lt;li&gt;As this is a static constructor, this is called before any member of SecureString type is accessed. Internally, only thing it does is, it sets a flag &lt;strong&gt;&lt;em&gt;supportedOnCurrentPlatform&lt;/em&gt;&lt;/strong&gt; to true or false. &lt;/li&gt;                    &lt;li&gt;To set this boolean value a call is made to Win32 native &lt;strong&gt;RtlDecryptMemory&lt;/strong&gt; method. This method is available as a resource named &lt;a&gt;&lt;/a&gt;&lt;em&gt;&lt;strong&gt;SystemFunction041&lt;/strong&gt;&lt;/em&gt; in Advapi32.dll. This method call is made to check wether current operating system supports encryption and decryption. &lt;/li&gt;                    &lt;li&gt;If this method entry is not found then &lt;em&gt;&lt;strong&gt;supportedOnCurrentPlatform &lt;/strong&gt;&lt;/em&gt;is set to false otherwise it is set to true. &lt;/li&gt;                    &lt;li&gt;All other constructors first check for this boolean value and if it is set to false then a &lt;strong&gt;NotSupportedException&lt;/strong&gt; is thrown.&lt;/li&gt;                 &lt;/ul&gt;               &lt;/li&gt;                &lt;li&gt;&lt;strong&gt;public SecureString()&lt;/strong&gt;                   &lt;ul&gt;                   &lt;li&gt;Checks &lt;em&gt;&lt;strong&gt;supportedOnCurrentPlatform &lt;/strong&gt;&lt;/em&gt;variable and throws &lt;strong&gt;NotSupportedException&lt;/strong&gt; exception if it is false. &lt;/li&gt;                    &lt;li&gt;If &lt;em&gt;&lt;strong&gt;supportedOnCurrentPlatform&lt;/strong&gt;&amp;#160; &lt;/em&gt;is true then buffer of 8 bytes is allocated. Methods used to allocate space are decorated with &lt;strong&gt;[ReliabilityContract(Consistency.WillNotCorruptState)] &lt;/strong&gt;attribute. This means that in the face of exceptional conditions, the method/s is guaranteed not to corrupt state. &lt;/li&gt;                    &lt;li&gt;In case of invalid buffer state or invalid memory allocation request, &lt;strong&gt;OutOfMemoryException()&lt;/strong&gt; will be thrown.&lt;/li&gt;                 &lt;/ul&gt;               &lt;/li&gt;                &lt;li&gt;&lt;strong&gt;internal SecureString(SecureString str)&lt;/strong&gt;                   &lt;ul&gt;                   &lt;li&gt;This constructor takes an existing SecureString object as a parameter and creates a new SecureString object with length and data of existing object. &lt;/li&gt;                    &lt;li&gt;This time there is no check for &lt;em&gt;&lt;strong&gt;supportedOnCurrentPlatform&lt;/strong&gt;&amp;#160; &lt;/em&gt;as already there is an active secure string object (passed as parameter) which indirectly means that SecureStrings are supported on this platform.&lt;/li&gt;                 &lt;/ul&gt;               &lt;/li&gt;                &lt;li&gt;&lt;strong&gt;public unsafe SecureString(char* value, int length)&lt;/strong&gt;                   &lt;ul&gt;                   &lt;li&gt;This is non CLS compliant as it uses pointers. &lt;/li&gt;                    &lt;li&gt;Contents of memory area specified by char* are copied to a new byte* . &lt;/li&gt;                    &lt;li&gt;Data content is then encrypted by making a call to Win32 native &lt;strong&gt;RtlEncryptMemory&lt;/strong&gt; method. This method is available as a resource named &lt;a&gt;&lt;/a&gt;&lt;em&gt;&lt;strong&gt;SystemFunction040&lt;/strong&gt;&lt;/em&gt; in Advapi32.dll. This process is called Protecting Memory and is implemented in the ProtectMemory() method explained in next section. &lt;/li&gt;                    &lt;li&gt;In case of error while protecting memory a &lt;strong&gt;CryptographicException&lt;/strong&gt; is thrown.                      &lt;br /&gt;&lt;/li&gt;                 &lt;/ul&gt;               &lt;/li&gt;             &lt;/ul&gt;           &lt;/li&gt;            &lt;li&gt;&lt;strong&gt;Encryption and Decryption &lt;/strong&gt;- SecureString class implements encryption and decryption using ProtectMemory() and UnProtectMemory() methods respectively               &lt;ul&gt;               &lt;li&gt;&lt;strong&gt;ProtectMemory()&lt;/strong&gt;                   &lt;ul&gt;                   &lt;li&gt;private method &lt;/li&gt;                    &lt;li&gt;&lt;strong&gt;&lt;/strong&gt;Some of the SecureString methods that use ProtectMemory() are,                       &lt;ul&gt;                       &lt;li&gt;Constructor - public unsafe SecureString(char* value, int length) &lt;/li&gt;                        &lt;li&gt;AppendChar(Char) &lt;/li&gt;                        &lt;li&gt;InsertAt(Int32, Char) &lt;/li&gt;                        &lt;li&gt;RemoveAt(Int32) &lt;/li&gt;                        &lt;li&gt;SetAt(Int32,Char)&lt;/li&gt;                     &lt;/ul&gt;                   &lt;/li&gt;                    &lt;li&gt;This method is decorated with&lt;strong&gt; [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]&lt;/strong&gt; attribute. Here Consistency.MayCorruptInstance means that in the face of exceptional conditions, the method is guaranteed to limit state corruption to the current instance. Whereas, Cer.MayFail means that in the face of exceptional conditions, the method might fail. In this case, the method will report back to the calling method whether it succeeded or failed. &lt;/li&gt;                    &lt;li&gt;Pseudocode&amp;#160; &lt;div class="csharpcode"&gt;                       &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;ProtectMemory()&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;{&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;   IF ((Length OF SecureStringObj IS NOT 0) AND (SecureStringObj IS NOT Encrypted))&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;    {&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;       BEGIN Constrained Execution Region&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;       {            &lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         CALL Win32Native.RtlEncryptMemory method AND Store Result IN @RES &lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         IF (@RES Shows Error)&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;            THROW CRYPTOGRAPHIC_EXCEPTION&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         ELSE&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;            SET SecureStringObj.IsEncrypted to TRUE;&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;        }&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;    }&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;p&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;}&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;&lt;/pre&gt;
                    &lt;/div&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;

              &lt;li&gt;&lt;strong&gt;UnProtectMemory()&lt;/strong&gt; 

                &lt;ul&gt;
                  &lt;li&gt;private method &lt;/li&gt;

                  &lt;li&gt;&lt;strong&gt;&lt;/strong&gt;Some of the SecureString methods that use UnProtectMemory() are, 

                    &lt;ul&gt;
                      &lt;li&gt;Constructor - public unsafe SecureString(char* value, int length) &lt;/li&gt;

                      &lt;li&gt;AppendChar(Char) &lt;/li&gt;

                      &lt;li&gt;InsertAt(Int32, Char) &lt;/li&gt;

                      &lt;li&gt;RemoveAt(Int32) &lt;/li&gt;

                      &lt;li&gt;SetAt(Int32,Char)&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;

                  &lt;li&gt;This method is decorated with&lt;strong&gt; [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]&lt;/strong&gt; attribute. Here Consistency.WillNotCorruptState means that in the face of exceptional conditions, the method is guaranteed not to corrupt state. Whereas, Cer.Success means that in the face of exceptional conditions, the method is guaranteed to succeed. &lt;/li&gt;

                  &lt;li&gt;Pseudo 
                    &lt;div class="csharpcode"&gt;
                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;UnProtectMemory()&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;{&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;   IF ((Length OF SecureStringObj IS NOT 0) AND (SecureStringObj IS Encrypted))&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;    {&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;       BEGIN Constrained Execution Region&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;       {            &lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         CALL Win32Native.RtlDecryptMemory method AND Store Result IN @RES &lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         IF (@RES Shows Error)&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;            THROW CRYPTOGRAPHIC_EXCEPTION&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;         ELSE&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;            SET SecureStringObj.IsEncrypted to FALSE;&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;        }&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;    }&lt;/font&gt;&lt;/pre&gt;

                      &lt;pre class="alt"&gt;&lt;font color="#004080" size="1" face="Verdana"&gt;}&lt;/font&gt;&lt;/pre&gt;
                    &lt;/div&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;

              &lt;li&gt;Both these methods are so implemented that in no case they can create instability in an application. &lt;/li&gt;

              &lt;li&gt;You can get more details about constraint execution region from MSDN
                &lt;br /&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;&lt;u&gt;PERFORMANCE&lt;/u&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;I think, comparing String and SecureString is not completely justified. SecureString was created taking in mind the shortcomings of String class. The way in which SecureString works like managing pointers, creating&amp;#160; constrained execution regions, encryption and decryption, it is bound to be on the slower side of performance. In this section I'll try to show you exactly how much slower SecureString is as compared to tradition String class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;STRING CREATION&lt;/strong&gt; 

      &lt;ul&gt;
        &lt;li&gt;&lt;strong&gt;Code Snippet&lt;/strong&gt; 

          &lt;div class="csharpcode"&gt;
            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;Int32 loopCounter = 0;&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;Int32 loopMaxCounter = 100000;&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;List&amp;lt;SecureString&amp;gt; secStrList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;SecureString&amp;gt;();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;Stopwatch sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stopwatch();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;sw.Reset();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;List&amp;lt;String&amp;gt; StrList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;String&amp;gt;();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;-----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Creating 100000 instances of strings&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (loopCounter = 0; loopCounter &amp;lt; loopMaxCounter; loopCounter++)&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;{&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    String str = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; Char[] { &lt;span class="str"&gt;'a'&lt;/span&gt; });&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    StrList.Add(str);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;}&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Created 100000 instances of string. Elapsed time (in milliseconds) &amp;quot;&lt;/span&gt; +&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;sw.Elapsed.Milliseconds.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;-----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;sw.Stop();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;sw.Reset();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;-----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Creating 100000 instances of secure strings&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (loopCounter = 0; loopCounter &amp;lt; loopMaxCounter; loopCounter++)&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;{&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;    SecureString obj = &lt;span class="kwrd"&gt;new&lt;/span&gt; SecureString();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;    obj.AppendChar(&lt;span class="str"&gt;'a'&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;    secStrList.Add(obj);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;}&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Created 100000 instances of secure string. Elapsed time (in milliseconds)&amp;quot;&lt;/span&gt; +&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;    sw.Elapsed.Milliseconds.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;sw.Stop();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;-----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
          &lt;/div&gt;
          &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/li&gt;

        &lt;li&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SucureStringin.NetPartII_1016A/image_6.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SucureStringin.NetPartII_1016A/image_thumb_2.png" width="524" height="93" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;ul&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

    &lt;li&gt;&lt;strong&gt;STRING MANIPULATION - Appending characters using AppendChar() method&lt;/strong&gt; 

      &lt;ul&gt;
        &lt;li&gt;Code Snippet 
          &lt;div class="csharpcode"&gt;
            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;SecureString secString = &lt;span class="kwrd"&gt;new&lt;/span&gt; SecureString();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;String str=String.Empty;&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;Stopwatch sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stopwatch();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;Int32 loopCounter = 0;&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;Int32 loopMaxCounter = 10000;&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;---------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Loop will run {0} times&amp;quot;&lt;/span&gt;,loopMaxCounter);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Current String Length  is {0}&amp;quot;&lt;/span&gt;, str.Length.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (loopCounter = 0; loopCounter &amp;lt; loopMaxCounter; loopCounter++)&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;{&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    str = str + &lt;span class="str"&gt;&amp;quot;a&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;}&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;String insertion completed in {0} milliseconds&amp;quot;&lt;/span&gt;,sw.Elapsed.Milliseconds.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Current length of String is {0}.&amp;quot;&lt;/span&gt;, str.Length.ToString());&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;sw.Stop();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;sw.Reset();&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;sw.Start();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Loop will run {0} times&amp;quot;&lt;/span&gt;, loopMaxCounter);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Current Secure String Length  is {0}&amp;quot;&lt;/span&gt;, str.Length.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (loopCounter = 0; loopCounter &amp;lt; loopMaxCounter; loopCounter++)&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;{&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;    &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;    {&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;        secString.AppendChar(&lt;span class="str"&gt;'a'&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;    }&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;    {&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;        Console.WriteLine(ex.ToString());&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;    }&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;}&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Secure String insertion completed in {0} milliseconds&amp;quot;&lt;/span&gt;, sw.Elapsed.Milliseconds.ToString());&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Current length of Secure String is {0}.&amp;quot;&lt;/span&gt;, secString.Length.ToString());&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;Console.WriteLine(&lt;span class="str"&gt;&amp;quot;-----------------------------------------------------------&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

            &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;sw.Stop();&lt;/pre&gt;

            &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;Console.Read();&lt;/pre&gt;
          &lt;/div&gt;
        &lt;/li&gt;
      &lt;/ul&gt;

      &lt;ul&gt;
        &lt;li&gt;Result&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SucureStringin.NetPartII_1016A/image_2.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SucureStringin.NetPartII_1016A/image_thumb.png" width="441" height="144" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;If we search for SecureString on web we can find a lot of questions going around related to pros and cons of SecureString usage. I'll compile a list of all of such type of questions in my next post. &lt;/p&gt;

  &lt;p&gt;Below are some reference sources that I used to get information related to secure string internals.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;u&gt;REFERENCES&lt;/u&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table border="1" cellspacing="0" cellpadding="2" width="820"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;strong&gt;&lt;font size="2"&gt;Subject&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;strong&gt;&lt;font size="2"&gt;Link&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;ReliabilityContract&lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.reliabilitycontractattribute.aspx" href="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.reliabilitycontractattribute.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.reliabilitycontractattribute.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;Consistency Enum&lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.consistency.aspx" href="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.consistency.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.consistency.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;Cer&lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.cer.aspx" href="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.cer.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.cer.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;Constrained Execution Region&lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.runtimehelpers.prepareconstrainedregions.aspx" href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.runtimehelpers.prepareconstrainedregions.aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.runtimehelpers.prepareconstrainedregions.aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;Win32Native.RtlDecryptMemory &lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/aa387692(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa387692(VS.85).aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/aa387692(VS.85).aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="193"&gt;&lt;font size="2"&gt;Win32Native.RtlEncryptMemory &lt;/font&gt;&lt;/td&gt;

      &lt;td valign="top" width="625"&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/aa387693(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa387693(VS.85).aspx"&gt;&lt;font size="2"&gt;http://msdn.microsoft.com/en-us/library/aa387693(VS.85).aspx&lt;/font&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9225667" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category></item><item><title>Download Problem for CAT.NET - Status Update</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/16/download-problem-for-cat-net-status-update.aspx</link><pubDate>Wed, 17 Dec 2008 02:34:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9229112</guid><dc:creator>cisg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9229112</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/16/download-problem-for-cat-net-status-update.aspx#comments</comments><description>&lt;p&gt;We are continuing to experience problems with the 32 bit download link for CAT.NET. We now estimate a fix by mid-day PST tomorrow (17th December). &lt;/p&gt;  &lt;p&gt;The 64 bit download link is active again &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=e0052bba-2d50-4214-b65b-37e5ef44f146&amp;amp;displaylang=en"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I will post here as soon as it is resolved. &lt;/p&gt;  &lt;p&gt;Our continued apologies. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9229112" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>Download Problem for CAT.NET - Status Update</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/16/download-problem-for-cat-net-status-update-1.aspx</link><pubDate>Tue, 16 Dec 2008 17:53:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9226129</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9226129</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/16/download-problem-for-cat-net-status-update-1.aspx#comments</comments><description>&lt;p&gt;We are continuing to experience problem with the links to download CAT.NET. We estimate a fix by 5pm today (16th December). &lt;/p&gt;  &lt;p&gt;I will post here as soon as it is resolved. &lt;/p&gt;  &lt;p&gt;Our continued apologies. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9226129" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CAT-NET/">CAT.NET</category></item><item><title>How the Anti-XSS 3.0 SRE Works</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/16/how-the-anti-xss-3-0-sre-works.aspx</link><pubDate>Tue, 16 Dec 2008 14:41:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9225344</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9225344</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/16/how-the-anti-xss-3-0-sre-works.aspx#comments</comments><description>&lt;p&gt;RV again...&lt;/p&gt;  &lt;p&gt;Last time around we looked at &lt;a href="http://blogs.msdn.com/cisg/archive/2008/10/24/a-sneak-peak-at-the-security-runtime-engine.aspx"&gt;SRE from a conceptual perspective&lt;/a&gt;, this time lets look at from a code perspective. Lets trace the program flow and understand in depth what SRE code does.&lt;/p&gt;  &lt;p&gt;SRE is a HttpModule, the main class file is AntiXssModule.cs which inherits from IHttpModule. In the Init() event of HttpModule we hook on to HttpApplication.PostMapRequestHandler() event which gets raised when an ASP.NET handler is processing the current user request. In this case we are trying to find out when the ASP.NET Page handler is processing the page. As System.Web.UI.Page is both a HttpHandler and Page class that an ASP.NET page represents, we can use it to hook on to the PreRender event. Additional checks are performed to determine whether the page is excluded or whether the class is marked with SupressAntiXssEncodingAttribute. &lt;/p&gt;  &lt;div&gt;   &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Init(HttpApplication context)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.LoadConfig(context, AppDomain.CurrentDomain.BaseDirectory + &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;                                             &lt;span style="color: #006080"&gt;&amp;quot;antixssmodule.config&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (objConfig != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         objApp = context;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         objApp.PostMapRequestHandler += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;                             EventHandler(objApp_PostMapRequestHandler);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;LoadConfig uses the Configuration/ModuleConfiguration.cs class to load and parse the XML to create an object of ModuleConfiguration class and stores it in Application state variable for which can be reused through out the lifetime of the application. There is a drawback with using this approach whenever you make a change to antixssmodule.config file, the application needs to be restarted for those changes to be applied.&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; objApp_PostMapRequestHandler(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//...validations &amp;amp; exclusion checks&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (objConfig != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strVirPath = objApp.Context.Request.FilePath;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (objConfig.IsPageExcluded(strVirPath.ToLower()))&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;         {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;         }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//attribute checks&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] attributes = ((Page)pageHandler).GetType().GetCustomAttributes&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(SupressAntiXssEncodingAttribute), &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (attributes.Length &amp;gt; 0)&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;     Page page = (Page)pageHandler;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;     &lt;span style="color: #008000"&gt;//Calling the static class to do the rest of the job&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;     XssProtection.Protect(page, objConfig);&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; 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: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060"&gt;  22:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In the PostMapRequestHandler after the checks we call the XssProtection.Protect method which hooks on to the Page.PreRender event. This way we wait till page gets processed, all properties and controls are built by ASP.NET. During prerender we iterate through the control collection of the page and find controls which need to be encoded. Specified properties in the configuration file are then encoded based on the encoding type using the AntiXss library. As the properties are dynamically defined in the XML configuration file, property values are set using reflection. In essence XssProtection class is the main class responsible for encoding the page controls properties.&lt;/p&gt;

&lt;p&gt;The following is a screenshot of Visio sequence diagram of the above things. 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SREInternals_8ACC/Sequence_2.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Sequence" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SREInternals_8ACC/Sequence_thumb.png" width="500" height="298" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For more information and insight into code please check &lt;a href="http://www.codeplex.com/antixss"&gt;http://www.codeplex.com/antixss&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks 
  &lt;br /&gt;RV&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9225344" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category></item><item><title>Anti-XSS 3.0 Beta and CAT.NET Community Technology Preview now Live!</title><link>http://blogs.msdn.com/b/cisg/archive/2008/12/15/anti-xss-3-0-beta-and-cat-net-community-technology-preview-now-live.aspx</link><pubDate>Mon, 15 Dec 2008 12:01:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9219313</guid><dc:creator>cisg</dc:creator><slash:comments>19</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9219313</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/12/15/anti-xss-3-0-beta-and-cat-net-community-technology-preview-now-live.aspx#comments</comments><description>&lt;p&gt;Mark Curphey here.....&lt;/p&gt;  &lt;p&gt;I am delighted to say that we have released two new free tools.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Download CAT.NET CTP (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en"&gt;32 bit here&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=e0052bba-2d50-4214-b65b-37e5ef44f146&amp;amp;displaylang=en"&gt;64 bit here&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;Download Anti-XSS 3.0 Beta (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;amp;displaylang=en"&gt;here&lt;/a&gt; and &lt;a href="http://www.codeplex.com/AntiXSS/"&gt;source code here&lt;/a&gt;) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;CAT.NET - Community Technology Preview&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;CAT.NET is a managed code static analysis tool for finding security vulnerabilities. It's exactly the same tool we use internally to scan all of our Line of Business (LOB) applications; it runs as a Visual Studio plug-in or as a stand-alone application. It was engineered by this group (CISG) and has been designed in partnership with the &lt;a href="http://blogs.msdn.com/ace_team/"&gt;ACE Team&lt;/a&gt; and &lt;a href="http://www.microsoft.com/research"&gt;Microsoft Research&lt;/a&gt;. The &lt;a href="http://blogs.msdn.com/ace_team/"&gt;ACE Team&lt;/a&gt; do thousands of code reviews for the internal line of business applications and for our external customers and have provided a wealth of real world knowledge and experience to the tool over the years. We will be posting several deep dive blogs this week on the inner workings of call graph and flow graph analysis and the algorithms behind CAT.NET from MSR. It is a technology preview; we appreciate that there are some performance and functionality limitations that we will be working on over time but we are already deep in discussion about the future design of CAT.NET and it's looking potentially very compelling!&lt;/p&gt;  &lt;p&gt;You can download the current CTP builds from MSDN (&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0178e2ef-9da8-445e-9348-c93f24cc9f9d&amp;amp;displaylang=en"&gt;32 bit here&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=e0052bba-2d50-4214-b65b-37e5ef44f146&amp;amp;displaylang=en"&gt;64 bit here&lt;/a&gt;) submit bugs and feedback to our Connect site (see post later this week for details). &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Anti-XSS 3.0 - Beta&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Cross Site Scripting (XSS) continues to plague web sites and among others things has become known as a common attack vector for Phishing attacks to distribute payloads to unsuspecting users. &lt;/p&gt;  &lt;p&gt;With this release we have taken a fresh look at how to provide protection to ASP.NET applications. As well as significantly better coverage for internationalisation in the core library and significantly improved performance, we are now are now shipping with the Security Runtime Engine (SRE), a .NET CLR plug-in that overrides default encoding's to render sites safe from XSS with zero code changes. While the SRE can not be used in every circumstance and cannot prevent every type of XSS, we believe it will provide great coverage in a wide variety of situations and forms another important layer in a defence in depth strategy. In testing on our own applications in Microsoft IT we have typically seen the ability to fix between 50% and 90% of XSS issues in an application out of the box with no code changes needed.&amp;#160; We are experimenting with preventing other attacks beyond XSS and expect to extend coverage in future releases. &lt;/p&gt;  &lt;p&gt;With this release we are also shipping with a performance test harness so you can test your own applications in pre-production and a copy of our own performance results conducted by the &lt;a href="http://blogs.msdn.com/ace_team/"&gt;ACE Team&lt;/a&gt; as well as a sample application that you can use to demonstrate the attack and how to fix it to your development teams. Another significant change is that Anti-XSS 3.0 is now being released as an open source tool using the MS-PL license at &lt;a href="http://www.codeplex.com/anitixss"&gt;Codeplex&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can download the current &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;amp;displaylang=en"&gt;beta binaries from MSDN here&lt;/a&gt; and source code from CodePlex &lt;a href="http://www.codeplex.com/AntiXSS"&gt;here&lt;/a&gt;. For Anti-XSS you can submit bugs and feedback directly to our CodePlex site &lt;a href="http://www.codeplex.com/AntiXSS"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Look for detailed posts about both Anti-XSS and CAT.NET on this blog this week and updates about these and related technologies on this blog.&lt;/p&gt;  &lt;p&gt;Subscribe via RSS &lt;a href="http://blogs.msdn.com/cisg/rss.xml"&gt;here&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Happy Holidays!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Mark&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9219313" width="1" height="1"&gt;</description></item><item><title>An Update on Some Upcoming Free Tools</title><link>http://blogs.msdn.com/b/cisg/archive/2008/11/13/an-update-on-some-upcoming-free-tools.aspx</link><pubDate>Thu, 13 Nov 2008 21:41:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9066986</guid><dc:creator>cisg</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9066986</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/11/13/an-update-on-some-upcoming-free-tools.aspx#comments</comments><description>&lt;p&gt;Mark Curphey here.....&lt;/p&gt;  &lt;p&gt;If the economy is getting you down here is some good news. We may have been quiet for the last few weeks but that's because we've been busy!&lt;/p&gt;  &lt;p&gt;Anti-XSS 3.0 is being released as an internal beta today. We are aiming for a public beta on codeplex within a few weeks. That's right, Anti-XSS 3.0 will be coming out as an open source project under the MS-PL license on codeplex. The project includes a completely re-written library with increased functionality and now running and near native speed and the new Security Runtime Engine (hooks the CLR and protects apps with no code changes). It includes a test harness, performance reports and all sorts of goodness. Watch this blog for the announcement. &lt;/p&gt;  &lt;p&gt;And now for the double whammy of good news. There will be a free public release of CAT.NET within the next few weeks. CAT.NET is our managed code review tool that plugs into Visual Studio. The initial release will be an alpha but we are working on significant updates to it over the next few months and plan to release several incremental updates. This tool contains DNA from Microsoft Research, the ACE Team and a host of great brain cells. It's very cool and the changes we are currently working on (well blogs about them in due course) just rock!&lt;/p&gt;  &lt;p&gt;Well publish release announcement and download URL's when they are ready. &lt;/p&gt;  &lt;p&gt;OK, back to changing diapers for me ;-) &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9066986" width="1" height="1"&gt;</description></item><item><title>Using Role Based Access Control in the .NET Framework - Part 2</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/29/using-role-based-access-control-in-the-net-framework-part-2.aspx</link><pubDate>Wed, 29 Oct 2008 11:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9019069</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9019069</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/29/using-role-based-access-control-in-the-net-framework-part-2.aspx#comments</comments><description>&lt;P&gt;Vineet Batta here again.. &lt;/P&gt;
&lt;P align=justify&gt;In my last blog I discussed how to use role based access control (RBAC) and described how we can restrict access to the method based on the &lt;STRONG&gt;declarative&lt;/STRONG&gt; method. In today's blog I will explain how to use&amp;nbsp; &lt;STRONG&gt;Imperative&lt;/STRONG&gt; role based demands. The end effect is the same, but using an imperative demand we can restrict access to a portion of code on a much more granular basis. Essentially, imperative roles based access control allows you to restrict portions of the method,&lt;STRONG&gt; &lt;/STRONG&gt;where as declarative demands allow you to restrict the entire method. &lt;/P&gt;
&lt;P align=justify&gt;To implement Imperative RBAC demands, do the following four steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;STRONG&gt;Add &lt;EM&gt;System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)&lt;/EM&gt; in the code.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;STRONG&gt;A Try/Catch block to catch underprivileged access attempts and to report errors.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;STRONG&gt;Create&lt;EM&gt; PrinicpalPermission&lt;/EM&gt; object, with properties set which reflect the restrictions you want to impose.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;STRONG&gt;A call to &lt;EM&gt;PrinicpalPermission.Demand()&lt;/EM&gt; method.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P align=justify&gt;The first two steps are exactly same as the declarative style, explained in my previous blog but the use of &lt;EM&gt;PrinicpalPermission&lt;/EM&gt; class is very different here. First you create new PrincipalPermission object. There are three overloaded constructors listed below.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;EM&gt;PrincipalPermission(Name, Role) &lt;/EM&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;EM&gt;PrinicpalPermission(PermissionState) &lt;/EM&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=justify&gt;&lt;EM&gt;PrincipalPermission(Name, Role, Authenticated) &lt;/EM&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Lets see all this in action in the example below (relate this to steps defined above);&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; main()&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step 1&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt; System.AppDomain.CuurentDomain.SetPrincipalPolicy(PrinicpalPolicy.WindowsPrincipal);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step2&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;try&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt; MyApplication app = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; MyApplication();&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  10:&lt;/SPAN&gt; app.UpdateUserProfile(334353);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  11:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  12:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt;(Exception error)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  13:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  14:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// Have your own robust error handling.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  15:&lt;/SPAN&gt; MessageBox.Show(&lt;SPAN style="COLOR: #006080"&gt;"You do not have access to execute this method"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  16:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  17:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  18:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  19:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; MyApplication &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  20:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  21:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; MyApplication(){};&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  22:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  23:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; UpdateUserProfile(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; empId)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  24:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  25:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step 3&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  26:&lt;/SPAN&gt; PrincipalPermission myperm = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; PrincipalPermission(&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;,&lt;SPAN style="COLOR: #006080"&gt;@"domain\SuperUsers"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  27:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step 4&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  28:&lt;/SPAN&gt; myperm.Demand();&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  29:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  30:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// Code to implement the feature here.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  31:&lt;/SPAN&gt; MessageBox.Show(&lt;SPAN style="COLOR: #006080"&gt;"You have access"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  32:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  33:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Let me explain step 3 and step 4 from the above code. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Step3 - The first argument to PrincipalPermission constructor is null, which indicates that no particular name is required. The second parameter specifies the role to which the users should be part of, so that the runtime can execute the code. In this example the user should belong to "domain\SuperUsers".&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Step 4 - The call to Demand() method will check for permissions as set in PrincipalPermission constructor. If the user does not have permission, the runtime will throw security exception. It's that simple to use Imperative RBAC to restrict access to code.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H4&gt;&lt;U&gt;Another scenario..&lt;/U&gt;&lt;/H4&gt;
&lt;DIV&gt;What if you want to branch execution of code based on the user's group membership? In this case you should use &lt;EM&gt;System.Security.WindowsPrincipal&lt;/EM&gt; class. The code snippet below demonstrates its use.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Create a WindowsIdentity object representing current user.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt; WindowsIdentity currentIdentity =  WindowsIdentity.GetCurrent();&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Create a WindowsPrincipal object representing current user.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt; WindowsPrincipal currentprincipal = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; WindowsPrincipal(currentIdentity ;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;(currentPrincipal.IsInRole(&lt;SPAN style="COLOR: #006080"&gt;@"domain\SuperUser"&lt;/SPAN&gt;))&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// If the user belongs to "domain\SuperUser" group then execute this code.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  10:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  11:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  12:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  13:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// else execute this code.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  14:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;H4&gt;&lt;U&gt;When Would You Use the Different RBAC Techniques?&lt;/U&gt;&lt;/H4&gt;
&lt;P&gt;Each technique ultimately accomplishes the same goal but each should be used in different circumstances.&lt;/P&gt;
&lt;TABLE border=2 cellSpacing=0 cellPadding=2 width=601&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=320&gt;&lt;FONT color=#800000&gt;&lt;STRONG&gt;Condition&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=277&gt;&lt;FONT color=#800000&gt;&lt;STRONG&gt;Preferred Technique&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=320&gt;Restrict access to an entire method.&lt;/TD&gt;
&lt;TD vAlign=top width=277&gt;Declarative RBAC&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=320&gt;Restrict access to all or portion of the code.&lt;/TD&gt;
&lt;TD vAlign=top width=277&gt;Imperative RBAC&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=320&gt;Branching code based users group membership.&lt;/TD&gt;
&lt;TD vAlign=top width=277&gt;WindowsPrincipal.IsInRole&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Back in a few days with more on securing the applications. Stay tuned.....&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9019069" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category></item><item><title>Using Role Based Access Control in the .NET Framework - Part 1</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/28/using-role-based-access-control-in-the-net-framework-part-1.aspx</link><pubDate>Tue, 28 Oct 2008 21:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9018857</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9018857</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/28/using-role-based-access-control-in-the-net-framework-part-1.aspx#comments</comments><description>&lt;P&gt;Hi Vineet Batta here..&lt;/P&gt;
&lt;P&gt;Consider a scenario where you want to write an assembly which contains methods that only certain type of users can call (domain\Administrators or a specific custom users account). So how can we control this within code and let the runtime enforce these security checks?&lt;/P&gt;
&lt;P&gt;Example scenario:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; Class MyApplication&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// You want that this method should only be called by users who are in domain\SuperUser account.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// You want to restrict the access by runtime.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; UpdateUserProfile(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; empId)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt; -- code to implement feature.&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;This is where Role Based Access Control (aka RBAC) can be effectively implemented. There are generally two ways to implement RBAC using either an&amp;nbsp; &lt;STRONG&gt;imperative &lt;/STRONG&gt;or &lt;STRONG&gt;declarative&lt;/STRONG&gt; method.&amp;nbsp; When we use declarative demands, we can require the user meet certain criteria before the runtime will execute the method. If the user lacks the permission, the runtime will throw the error which we can react to. Today, I will focus on declarative style and show case how easy it is achieve this and in part 2 well cover the imperative method. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;First lets discuss about few classes.&lt;/DIV&gt;
&lt;P&gt;&lt;EM&gt;System.Security.Permission.PrinicpalPermission&lt;/EM&gt; class and the related &lt;EM&gt;System.Security.Permission.PrinicpalPermissionAttribute &lt;/EM&gt;class will enable you to check active principal (aka USER account information) under which the runtime will execute the code. &lt;EM&gt;PrinicpalPermission&lt;/EM&gt; can be used to demand that the identity of the active principal match this information. &lt;EM&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;PrinicpalPermission&lt;/EM&gt; has three core properties :&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Authentication&lt;/STRONG&gt; : A boolean value. if this is set to true, the permission requires the user to be authenticated. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt; : The string that matches the identity of the user. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Role &lt;/STRONG&gt;&amp;nbsp; : The string that must match one of the principal's role. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;One of the most used methods is &lt;STRONG&gt;&lt;EM&gt;PrinicpalPermission.Demand(). &lt;/EM&gt;&lt;/STRONG&gt;It does the heavy lifting for us and you will see it in action in a sec...&lt;/P&gt;
&lt;P&gt;To use declarative RBAC demands, we must complete the following three steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;Add the following code to specify principal security policy.&lt;/STRONG&gt; &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2. &lt;STRONG&gt;A Try/Catch block to catch underprivileged access attempts and to report errors&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3. &lt;STRONG&gt;Annotate the method with &lt;EM&gt;PrinicpalPermission&lt;/EM&gt; attribute to declare method's access requirements. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Complete Example:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; main()&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// Step 1.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt; System.AppDomain.CurrentDomain.SetPrincipalPoilicy(PrincipalPoilicy.WindowsPrincipal);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step 2.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;try&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  10:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  11:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  12:&lt;/SPAN&gt; myApplication app = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; myApplication();&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  13:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  14:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// call the method for which RBS has be declared.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  15:&lt;/SPAN&gt; app.UpdateUserProfile(1234);&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  16:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  17:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  18:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt;(exception error)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  19:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  20:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// Catch and display message. This is just an example. You &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  21:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;// should implement you own robust error handling.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  22:&lt;/SPAN&gt; MessageBox.Show(&lt;SPAN style="COLOR: #006080"&gt;" You do not have access to run this function"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  23:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  24:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  25:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  26:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  27:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  28:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; myApplication&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  29:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  30:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  31:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; myApplication();&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  32:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  33:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  34:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #008000"&gt;//Step 3.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  35:&lt;/SPAN&gt; [PrincipalPermission(SecurityAction.Demand, Role = &lt;SPAN style="COLOR: #006080"&gt;@"domain\SuperUsers"&lt;/SPAN&gt;)]&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  36:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; updateUserProfile(&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; empid)&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  37:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  38:&lt;/SPAN&gt; --- write code here that should only be executed by specific users.&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  39:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  40:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  41:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  42:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; 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: consolas, 'Courier New', courier, monospace; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060"&gt;  43:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;In step3 you see that that the users in the role ="domain\SuperUsers'' only can only execute this method. If any one who is not part of this group tries to execute, the runtime will throw appropriate exception. Of course we always need to fail closed!!&lt;/P&gt;
&lt;P&gt;In the next blog I will show how the Imperative approach can be used and then compare the advantages and disadvantages of the two schemes. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9018857" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Secure+Coding/">Secure Coding</category></item><item><title>ISO/IEC JTC 1/SC 27 - Working Group - Trip Report</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/24/iso-iec-jtc-1-sc-27-working-group-trip-report.aspx</link><pubDate>Fri, 24 Oct 2008 16:31:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9014697</guid><dc:creator>cisg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9014697</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/24/iso-iec-jtc-1-sc-27-working-group-trip-report.aspx#comments</comments><description>&lt;p&gt;Hi Andreas Fuchsberger here again.... &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The most recent &lt;a href="http://www.jtc1sc27.din.de/cmd?level=tpl-home&amp;amp;contextid=jtc1sc27&amp;amp;languageid=en"&gt;ISO/IEC JTC1/SC 27&lt;/a&gt; (Subcommittee) Working Group (WG) meetings took place from 6&lt;sup&gt;th&lt;/sup&gt; &amp;#8211; 10&lt;sup&gt;th&lt;/sup&gt; October 2008 in Limassol, Cyprus. As is set out by SC27&amp;#8217;s charter all 5 Working Group meetings took place in parallel, allowing National Body (NB) experts to participate in more than WG during the week. The 5 Working Groups are:&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 1: Information Security Management Systems (ISMS)&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 2: Cryptography and Security Mechanisms&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 3: Security Evaluation Criteria&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 4: Security Controls and Services&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 5: Privacy and Identity Management&lt;/p&gt;  &lt;p&gt;As it physically not possible to attend all meetings simultaneously, this reports details results for the WG 2, 4 and 5, that were obtained either through attendance by the author or trusted reports available to the author.&lt;/p&gt;  &lt;p&gt;Access currently to the various stages of the Working Drafts (WD) used to produce International Standards (IS) are usually restricted to active participants in the standards process. However it is usually easy to gain access by contacting your &lt;a href="http://www.jtc1sc27.din.de/cmd?level=tpl-bereich&amp;amp;menuid=63159&amp;amp;cmsareaid=63159&amp;amp;languageid=en"&gt;National Body of ISO/IEC JTC 1/SC 27.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Report from WG 2: Cryptography and Security Mechanisms&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;WG2 had a busy meeting and a large number of standards and documents were edited during the working group sessions and new versions will be available by the editors and distributed to National Bodies (NBs) for review at the next meeting (Note: NBs are not required to distribute Working Drafts (WDs), however it is common practice):&lt;/p&gt;  &lt;p&gt;The WG 2 meeting was well attended with 41 participants in total, representing 12 National Bodies; as the Japanese NB had the strongest attendance with 17 participants.&lt;/p&gt;  &lt;p&gt;Noteworthy is the update of Standing Document &lt;a href="http://www.jtc1sc27.din.de/sce/SD12"&gt;SD 12 Cryptographic algorithms and key lengths&lt;/a&gt;, to be used as guidance which cryptographic algorithms should be used in production systems with their appropriate recommended key lengths. Also noteworthy is the new Study Period on Secret Sharing Mechanisms prompted by the presentation to WG 5 on Privacy Enhancing Technologies by the Japanese expert, Kazue Sako.&lt;/p&gt;  &lt;p&gt;WG 2 initiated one New Work Item on Lightweight Cryptography and the following new Study Periods:&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Lightweight cryptographic mechanisms&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Key establishment mechanisms for multiple entities and German NB proposal on Group key management&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Secret sharing mechanisms&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Parsing ambiguity attacks &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Report from WG4: Security Controls and Services&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;WG4 had a busy meeting and number of standards and documents were edited during the working group sessions and new versions will be available by the editors and distributed to National Bodies (NBs) for review at the next meeting (Note: NBs are not required to distribute Working Drafts (WDs), however it is common practice):&lt;/p&gt;  &lt;p&gt;The WG 4 meeting was well attended with 62 participants in total, representing 16 National Bodies, the Japanese NB had the strongest attendance with 11 participants. &lt;/p&gt;  &lt;p&gt;WG 5 is a relatively new WG as such this was only the 6&lt;sup&gt;th&lt;/sup&gt; meeting. This is reflected through by the relevant immaturity of the documents so far, the majority being WDs, with exception of Network Security Part 1, which was inherited from WG 1 when WG 4 was created.&lt;/p&gt;  &lt;p&gt;Of particular interest to is the progress that has been made in Application security: part 1. &lt;/p&gt;  &lt;p&gt;WG 4 imitated 2 new Work Items: &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Guidelines for Identification, Collection and/or Acquisition and Preservation of Digital Evidence&lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Guidelines for Security of Outsourcing&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Report from WG5: Privacy and Identity Management&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;WG5 had a busy meeting and number of standards and documents were edited during the working group sessions and new versions will be available by the editors and distributed to National Bodies (NBs) for review at the next meeting (Note: NBs are not required to distribute Working Drafts (WDs), however it is common practice):&lt;/p&gt;  &lt;p&gt;The WG 5 meeting was well attended with over 40 participants in total. The terms of reference of WG 5 covers both Privacy and Identity Management, and experts were present from both areas. &lt;/p&gt;  &lt;p&gt;WG 5 is a relatively new WG as such this was only the 6&lt;sup&gt;th&lt;/sup&gt; meeting. This is reflected through by the relevant immaturity of the documents so far, the majority being WDs. &lt;/p&gt;  &lt;p&gt;Noteworthy is the progression of 2900 Privacy Framework to CD stage. The Study Period (SP) on Access Control Mechanisms prompted by the Chinese NB contribution during the 4&lt;sup&gt;th&lt;/sup&gt; WG 5 meeting, for which the author was Rappateur was concluded with recommendation to SC 27 Plenary to start on new SC 27 wide Study Period on Access Control. The author was volunteered as Rappateur for the new Study Period and also volunteered for the WG 5 drafting committee, that met after the closing the WG meeting throughout the week.&lt;/p&gt;  &lt;p&gt;WG 5 imitated 2 new Work Items: &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Privacy Capability Maturity Model and &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Requirements for Relative Anonymity with Identity Escrow &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Next Meetings&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The next SC 27 WG meetings were agreed as:&lt;/p&gt;  &lt;p&gt;&amp;#183; 2009-05-04 - 2009-05-08 Beijing, China&lt;/p&gt;  &lt;p&gt;&amp;#183; 2009-11-02 - 2009-11-06 Redmond, WA, USA&lt;/p&gt;  &lt;p&gt;&lt;b&gt;TCG Fast track&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The regular WG meetings were followed by a one day meeting to agree to fast track the adoption of the &lt;a href="https://www.trustedcomputinggroup.org/home"&gt;Trusted Computing Group&lt;/a&gt; (TCG) standards.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9014697" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Security+Standards/">Security Standards</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/ISO/">ISO</category></item><item><title>ISO SC27 Introduction and History</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/24/iso-sc27-introduction-and-history.aspx</link><pubDate>Fri, 24 Oct 2008 16:29:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9014696</guid><dc:creator>cisg</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9014696</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/24/iso-sc27-introduction-and-history.aspx#comments</comments><description>&lt;p&gt;Hi Andreas Fuchsberger here.....&lt;/p&gt;  &lt;p&gt;In order to better understand a report I am about to post next on a recent ISO security meeting I thought I would include some additional information about the language used in SC 27 and how SC 27 standards are created. &lt;/p&gt;  &lt;p&gt;SC 27 is a sub-committee of the Joint Technical Committee (JTC1) of the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC). The International Organization for Standardization (&lt;i&gt;Organisation internationale de normalisation&lt;/i&gt;) usually known as ISO is an international-standard-setting body composed of representatives from various national standards organizations. Created in 1947, the organization creates worldwide proprietary industrial and commercial standards. It is headquartered in Geneva, Switzerland. The International Electrotechnical Commission (IEC) is a not-for-profit, non-governmental international standards organization that prepares and publishes International Standards for all electrical, electronic and related technologies. Currently there exists only one joint technical committee (JTC1). JTC1 standards use the prefix ISO/IEC. &lt;/p&gt;  &lt;p&gt;The correct abbreviation used to indicate SC 27 output is ISO/IEC JTC1/SC 27. All output produced in SC 27 is given a project number. A definitive list of current projects is published in SC 27 Standing Document (SD) &lt;/p&gt;  &lt;p&gt;SC 27 started worked in the early 1990s originally split into three working groups: (1) Security Management, (2) Cryptographic Mechanisms and (3) Security Evaluation Criteria. Much of the attention and success was derived from the WG 1 adoption of British Standard BS7799 and transformation and publication of originally ISO/IEC 17799 Parts 1 and 2 for Information Security Management and accompanying standards. The ISO/IEC 17799 series was later renamed to become the ISO/IEC 27000 Information Security Management series. Due to its success WG 1 was split into 3 Working Groups: &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 1: Information Security Management Systems (ISMS) &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 4: Security Controls and Services &lt;/p&gt;  &lt;p&gt;&amp;#183; &amp;#183; Working Group 5: Privacy and Identity Management &lt;/p&gt;  &lt;p&gt;A definitive list of projects including all published standards and work in progress is made available through Standing Document (SD) 7 Catalogue of SC 27 Projects and Standards. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Progression of Standards&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;Although the editing work of creating a new standard is performed by National Body experts during the Working Group meetings, it is SC 27 that delegates the authority to start a new standard. A national body may propose a New Work Item (NWI) by providing input to a WG meeting, or WG may initiate a new Study Period on a particular topic, usually also prompted by a NB or a subject matter expert. Both NWIP and SP are circulated by the SC 27 Secretariat for distribution through National Bodies. NB then vote on starting the process for creating new International Standard. &lt;/p&gt;  &lt;p&gt;Once an editor is found, either through a volunteer or by a call for contributions to the NBs, the process for a new International Standard, the editor produces a series of Working Drafts. NBs are not required to distribute Working Drafts (WDs), however it is common practice. NBs consult their own experts for contributions to WDs. Editors then collect the international contributions and during the editing sessions of the WG meetings either accept, reject or otherwise find a compromise to the comments made by the National Body experts. SC 27 relies usually on finding a consensus by taking the NB comments into account, rarely does it come to a vote on accepting or rejecting a comment. Depending on the NB it may be more appropriate to let the NB withdraw a comment than reject it outright. After a WD draft has gone through multiple iterations and during the editing session it is agreed that the document has reached an acceptable level of maturity the WG can request SC 27 for a delegation of authority to move the document to Committee Draft (CD) stage. CDs are distributed to the NBs for study and comment. Once the CD has reached a further level of maturity, the WG can request to move to Final CD stage. FCDs are distributed by NBs for comment and are subject to a NB postal vote. For a FCD to pass it needs a three quarters majority SC 27 P-member NBs. Thereafter SC 27 takes over the progression of the standard to Daft International Standard (DIS) and then to publication by JTC1 to International Standard (IS). &lt;/p&gt;  &lt;p&gt;The whole process takes now on average 2 &amp;#8211; 2.5 years. This is a significant improvement since the mid 1990s when the process has taken up to 7 years. This used to be one of the major criticisms of the ISO Standards process. This and the fact that most ISO/IEC standards are chargeable, which is in contrast to the Internet standards RFCs and other industry standards.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9014696" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Security+Standards/">Security Standards</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/ISO/">ISO</category></item><item><title>A Sneak Peak at the Security Runtime Engine</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/24/a-sneak-peak-at-the-security-runtime-engine.aspx</link><pubDate>Fri, 24 Oct 2008 11:14:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9014363</guid><dc:creator>cisg</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9014363</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/24/a-sneak-peak-at-the-security-runtime-engine.aspx#comments</comments><description>&lt;p&gt;RV here again...&lt;/p&gt;  &lt;p&gt;Traditionally security fixes are applied to specific pieces of code where a vulnerability exists which usually involves some development and testing effort. Imagine a system where an application is instantly secured by simple configuration. I am specifically talking about ASP.NET applications where Cross site scripting and SQL injection are some of the most common vulnerabilities found. This is exactly what the Security Runtime Engine (SRE) does, allows you to instantly turn on and protect applications which are already developed and deployed. This is very important for legacy applications which are already developed and usually don't have resources for any new development.&lt;/p&gt;  &lt;p&gt;We have been working on a runtime engine specially for ASP.NET applications which could provide blanket protection to some of the common web application vulnerabilities. When I say blanket protection I mean single point of deployment and protection for the entire application. Thus we designed the SRE as an HTTP module which works at the IIS/ASP.NET layer providing protection against certain attacks. This is different from a web application firewall, it hooks the CLR and so doesn't operate on network protocol stream as it passes the network. As such it's tightly coupled to the application; an important and significant difference. Currently it provides protection against Cross Site Scripting by automatically encoding the controls. &lt;/p&gt;  &lt;p&gt;It does this by walking the controls in the requested page and automatically encoding data in specific properties for example Label.Text. It can be customized to walk and encode (override) only specific controls such as Label, HyperLink, CheckBox etc. and additionally the type of encoding used can also specified for each individual property of a control. This customization enabled using a configuration file in the web root. SRE leverages the upcoming Anti-XSS library to ensure ultimate XSS protection.&lt;/p&gt;  &lt;p&gt;Apart from simple encoding, SRE also contains some advanced features for better usability and adoption. Notably the following 3 features standout;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Double Encoding Protection &lt;/li&gt;    &lt;li&gt;Encode Derived Controls &lt;/li&gt;    &lt;li&gt;Suppressions &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The double encoding protection feature ensures that there is no double encoding possibility. Double encoding problem occurs if you encode data twice. SRE would make sure that it's encoding does not double encode the data. The encoding derived controls feature allows the derived controls to be automatically encoded if the base controls are already configured, for example if you create your own label control using the System.Web.UI.WebControls.Label then you control will&amp;#160; automatically be secured without any additional configuration. The suppressions feature allows you to suppress encoding for specific pages or controls. If you want to encode programmatically or your page does not use any input, you could suppress encoding in that page. Ultimate flexibility! This can be done by adding the specific page path to the configuration file. Note that SRE encoding performance is similar to Anti-XSS library. We have had the ACE Performance testing team do an analysis and it runs at near native speed. We will be shipping both tools wit a performance test and a test harness. So enabling SRE is similar to implementing AntiXSS library but with added bonus of not having to implement any code changes and yet get protection across the entire application. You can think of it as the ability to have secure encoding out of the box. Of course this will break many existing applications which is one reason why the .NET framework couldn't implement this by default. &lt;/p&gt;  &lt;p&gt;SRE also includes a configuration utility which reflects on the compiled ASP.NET application binary and creates a custom configuration file based on the controls in the binary. The configuration utility includes a master file which contains the list of all the controls, their properties and encoding type needed. This custom configuration file is very useful in making sure the proper configuration is applied to the web application.&lt;/p&gt;  &lt;p&gt;In future SRE could be able to provide protection against certain other classes of web application attacks (in fact we already have work happening on that). SRE is code complete and in the final stages of testing.&amp;#160; We will have an internal beta soon and a public one within the next few months. &lt;/p&gt;  &lt;p&gt;Check our blog for the beta announcement!&lt;/p&gt;  &lt;p&gt;Thanks &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;Anil RV&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9014363" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/cisg/archive/tags/Anti_2D00_XSS/">Anti-XSS</category><category domain="http://blogs.msdn.com/b/cisg/archive/tags/CISG/">CISG</category></item><item><title>Introducing SecurityNow</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/17/introducing-securitynow.aspx</link><pubDate>Fri, 17 Oct 2008 13:52:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9002856</guid><dc:creator>cisg</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=9002856</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/17/introducing-securitynow.aspx#comments</comments><description>&lt;p&gt;Mark Curphey here.....&lt;/p&gt;  &lt;p&gt;A few months back I challenged some of my team to build a &amp;quot;Proof of Concept&amp;quot; (POC) that would;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;demonstrate how we could apply some of the ideas and concept we had been talking about such as BPM and BI &lt;/li&gt;    &lt;li&gt;show how Microsoft's technology stack can be applied to the security management space &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;With just a few weeks of work (we really do have an incredibly talented team) we produced &amp;quot;SecurityNow&amp;quot;. The POC took it's name from the excellent connected systems demo called &lt;a href="http://www.dinnernow.net"&gt;DinnerNow&lt;/a&gt;. We wanted to take a specific scenario and in this case chose to look at line of business application security assessments in a corporate environment. We could have easily chosen incident management, risk assessment, network vulnerability management etc. but the information security team here has the &lt;a href="http://blogs.msdn.com/ace_team/"&gt;ACE Team&lt;/a&gt; who are responsible for security assessment of our Line of Business (LOB) applications and it was what Tom Cruise would call a &amp;quot;target rich&amp;quot; scenario. The scenario we chose was actually made up of a set of smaller scenarios and in my experience is typical of how many corporations would like to do their line of business application security assessments. &lt;/p&gt;  &lt;p&gt;Scenario 1 - The systems owner schedules an assessment&lt;/p&gt;  &lt;p&gt;Scenario 2- We automated the execution of security assessment tools&lt;/p&gt;  &lt;p&gt;Scenario 3 - The system hands off to a trained analysts to do the manual assessment &lt;/p&gt;  &lt;p&gt;Scenario 4 - Automated the tracking of the assessment status&lt;/p&gt;  &lt;p&gt;The POC specifically looked at applying Windows Workflow Foundation (WWF) and PerformancePoint server (we have some stuff in the brew looking at WPF, Oslo and WCF now so watch the blog in the future). &lt;/p&gt;  &lt;p&gt;The engineers will be blogging about the specifics in detail in the coming weeks so I will just provide a high-level overview by way of introduction with some teaser screen shots. &lt;/p&gt;  &lt;p&gt;When you first go the POC you get the coverage below to navigate to the various scenarios.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_2.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_thumb.png" width="644" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It's worth jumping straight to the business process designer. Behind the POC is a state machine workflow (what's shown below is actually one of the states) which then executes on the business process engine and is monitoring by business activity monitoring (or BAM). We re-hosted the .NET workflow designer and built a state machine and set of activities to automatically pull code from Team Foundation Server, compile it (check) and run our manage code review tool CAT.NET (you'll be hearing lots more about that on the blog in the coming weeks).&amp;#160; &lt;/p&gt;  &lt;p&gt;We believe visual modelling and simulation of security processes will be huge. You can literally drag and drop activities onto the design surface and build an application in minutes. I posted about the Tenets &lt;a href="http://securitybuddha.com/2008/02/28/tenets-of-effective-bpm/"&gt;of BPM for Security on my personal blog&lt;/a&gt; a while back. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_6.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_thumb_2.png" width="644" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We built a simple UI (not shown here) that allows the user to come along and schedule an assessment by providing the location of the code in his / her Team Foundation Server. We capture his / her project details from the GAL (Active Directory) and capture some additional project related information. It takes less than 60 seconds to request and schedule an assessment!!&amp;#160; When submitted we automatically pull the code from the project teams team Foundation Server, compile it and run our automated tools over it. We then (and this is where it gets good) automatically enter any defects back to the team as TFS work items. If they have any Sev 1 bugs we put the work flow on hold until they have closed off those bugs. When they interact with the workflow we of course verify that they have indeed closed them out before handing off the assessment to the analyst who picks up his review of the things automated tools can't (or do a bad job of) finding. The screen shot below is a status report which basically queries the workflow in operation. You can see this particular case is on hold as there were Sev1 bugs found (this is all dummy data of course). &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_8.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_thumb_3.png" width="644" height="444" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The analyst or the system owner can query the status of the process and any results in real time. Below is the current status of the security defects that were found.&amp;#160; The reports below are build using PerformancePoint, our Business Intelligence suite. Our development team in India has vast experience in building huge high performance data warehouses and you should expect to hear a lot from us about data warehouses for security in the coming months. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_10.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/IntroducingSecurityNow_A6BD/image_thumb_4.png" width="644" height="444" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I'll leave it there for now. It was just an introduction. The engineers will follow-up with a series of posts about the nuts and bolts and I expect to follow-up in a few weeks with some news and more details about our plans for security management tools.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9002856" width="1" height="1"&gt;</description></item><item><title>Secure Strings in .NET - Part I</title><link>http://blogs.msdn.com/b/cisg/archive/2008/10/08/secure-strings-in-net-part-i.aspx</link><pubDate>Wed, 08 Oct 2008 18:25:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8991503</guid><dc:creator>cisg</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/cisg/rsscomments.aspx?WeblogPostID=8991503</wfw:commentRss><comments>http://blogs.msdn.com/b/cisg/archive/2008/10/08/secure-strings-in-net-part-i.aspx#comments</comments><description>&lt;p&gt;Hi Gaurav Sharma here.......&lt;/p&gt;  &lt;p&gt;I am a developer on the CISG India team based in Hyderabad and I joined Microsoft four months ago. I love playing computer games and recently finished Call of duty 4. For the last three years I've been working with .NET and have worked on different kinds of applications that include ERP solutions, utilities and web portals. Apart from computer games I like watching soccer; there was a time (long back) when I used to watch each and every match of English premier league. I've a &lt;a href="http://fun-with-blackhawk.blogspot.com/"&gt;blog&lt;/a&gt; that I last updated when I joined MS. This looks like enough information about me, let us start with our secure string story. &lt;/p&gt;  &lt;p&gt;A few months back I was looking into improvements that Microsoft made to it's .NET base class library since its inception and I stumbled upon a class named Secure String. I found that exiting and made a small &lt;a href="http://fun-with-blackhawk.blogspot.com/search/label/Secure%20String"&gt;blog entry&lt;/a&gt; related to this new class.     &lt;br /&gt;    &lt;br /&gt;In this write up I'll try to focus on the need for secure string class as well as its internal working and usage. I'll also try to do a feature comparison between String and SecureString class. You will find code examples and IL code with theoretical explanations. There are a few tools that I will use for creating code and IL samples. These are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a target="_blank" href="http://msdn.microsoft.com/en-us/vstudio/default.aspx"&gt;Visual Studio 2008&lt;/a&gt;&lt;/strong&gt;       &lt;br /&gt;I'll use Visual studio for creating code samples. If you do not have Visual studio installed on your system you can download and install the free express version of our beloved IDE. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;.NET class viewer&lt;/strong&gt;       &lt;br /&gt;I will use .NET Reflector but you can use any tool of your choice. &lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/aa309387(VS.71).aspx"&gt;ILDASM.EXE&lt;/a&gt; &lt;/strong&gt;      &lt;br /&gt;Another great tool and will be used to look at IL code, manifest information and assembly metadata &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Memory Profiler        &lt;br /&gt;&lt;/strong&gt;I'll try to use this tool to show how object creation of string class differs from secure string &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The structure of this two part write up (this is part one) is as follows; &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Part I      &lt;ul&gt;       &lt;li&gt;Introduction &lt;/li&gt;        &lt;li&gt;SecureString Class &lt;/li&gt;        &lt;li&gt;Members &lt;/li&gt;        &lt;li&gt;Usage &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Part 2      &lt;ul&gt;       &lt;li&gt;Internals &lt;/li&gt;        &lt;li&gt;SecureString vs. String class          &lt;ul&gt;           &lt;li&gt;Performance &lt;/li&gt;            &lt;li&gt;Usability &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Misc. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let's start our journey to explore SecureString,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;INTRODUCTION&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Since the inception of .NET programming, I doubt whether there is any other class used more frequently than the String class. We can use string to represent any textual and literal data like name, location, occupation etc. There are four ways in which we can represent individual character and their collections:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;System.Char &lt;/li&gt;    &lt;li&gt;System.String &lt;/li&gt;    &lt;li&gt;System.Text.StringBuilder, and &lt;/li&gt;    &lt;li&gt;System.Security.SecureString &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;System.String is an ordered set of characters that is immutable. String is a reference type so every string object that we create lives on the heap rather than on the thread stack. Because strings are immutable, once they are created we can not change them. We can not add or remove or manipulate existing string objects. Whenever we try to manipulate string objects we discard old objects (they are still there on heap) and create new ones. Let's see a code snippet,    &lt;br /&gt;&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Gaurav.Samples.SecureString&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; name = &lt;span class="str"&gt;&amp;quot;Gaurav&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            name = name + &lt;span class="str"&gt;&amp;quot;Sharma&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            name = name + &lt;span class="str"&gt;&amp;quot;Mr.&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            Console.WriteLine(name);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            Console.Read();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;This will create three string objects. When we add &amp;quot;Sharma&amp;quot; to the already existing string name, a new string object is created and the name variable now refers to this new object. The old string object is marked for garbage collection. Same thing happens again when we try to append &amp;quot;Mr.&amp;quot; to name. A new object is created and we have two old objects marked for garbage collection. The next garbage collection run will clear out these two objects. &lt;/p&gt;

&lt;p&gt;Now suppose you have a application that stores username, password and credit card number in string objects. These string objects are basically in memory character arrays and if there is any unsafe or unmanaged code is allowed to execute, that code can snoop around the process's address space, locate the string with sensitive data and can use this data in a bad way. &lt;/p&gt;

&lt;p&gt;Strings are not pinned objects. Pinned objects are those whose memory can not be compacted by garbage collection. As strings are not pinned objects, our garbage collector is&amp;#160; free to move strings in memory. When string objects are moved several garbage copies of string data are created whose memory will be reclaimed by the garbage collector during later runs. Having so many copies of data (especially if sensitive) can create issues. &lt;/p&gt;

&lt;p&gt;String keeps a plain text copy i.e. not encrypted, so our data is under continuous danger of being read by some one who can read our process's memory. If our string object is used for a small time span and then garbage collected, it's possible that the common language runtime (CLR) will not reuse the object's memory immediately (this depends on the generation of the object). This can be a potentially compromising situation with our strings data left in memory. Moreover as strings are immutable you can not overwrite them with blank data, the code below for example will not clear out any data. &lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Gaurav.Samples.SecureString&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        {&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; name = &lt;span class="str"&gt;&amp;quot;Gaurav&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="rem"&gt;//this will create new object and will not clear out old object's data&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            name = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            Console.WriteLine(name);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            Console.Read();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If at any time you run out of memory, string memory contents can get into SWAP files, where they can be a lot easier to access by the bad guys (hackers). Due to these issues Microsoft introduced added another secure string class in FCL,&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Class Name:&lt;/strong&gt; SecureString &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Namespace:&lt;/strong&gt; System.Security &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Assembly:&lt;/strong&gt; mscorlib.dll &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;SECURE STRING CLASS&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some facts about secure string class are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;When a new object of secure string class is constructed, the CLR allocates a block of &amp;quot;&lt;strong&gt;unmanaged&lt;/strong&gt;&amp;quot; memory that contains an array of characters. The garbage collector is not aware of this memory block because this is unmanaged. &lt;/li&gt;

  &lt;li&gt;Data is encrypted using &lt;strong&gt;&lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms995355.aspx"&gt;Data Protection API&lt;/a&gt; or DPAPI&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;Methods available in Secure String class like AppendChar, InsertAt...first decrypts the data then performs the action and then again re-encrypts the data. &lt;/li&gt;

  &lt;li&gt;This class implements the &lt;strong&gt;IDisposable&lt;/strong&gt; interface which means that you can clean out your object deterministically. Dispose method zeroes out the content of the memory buffer. &lt;/li&gt;

  &lt;li&gt;This class is also derived from &lt;strong&gt;&lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/system.runtime.constrainedexecution.criticalfinalizerobject.aspx"&gt;CriticalFinalizerObject&lt;/a&gt;&lt;/strong&gt;. This guarantees that object's &lt;strong&gt;finalizer&lt;/strong&gt; method is called , which means characters will be zeroed out and memory will be freed.&amp;#160; &lt;/li&gt;

  &lt;li&gt;Unlike string, objects are mutable. This means that if we pass this object to different functions, only one copy of object will be there. &lt;/li&gt;

  &lt;li&gt;This is non CLS compliant (use of pointers). &lt;/li&gt;

  &lt;li&gt;This is a sealed class (like all data types). &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;MEMBERS&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MSDN provides a good information about members of&amp;#160; the SecureString class. &lt;a title="http://msdn.microsoft.com/en-us/library/system.security.securestring_members.aspx" href="http://msdn.microsoft.com/en-us/library/system.security.securestring_members.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.security.securestring_members.aspx&lt;/a&gt; page will give you enough information that will equip you for SecureString usage. For your convenience I'll add member summary here, but for latest information you should always check MSDN.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/memberInfo.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="memberInfo" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/memberInfo_thumb.png" width="700" height="506" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;strong&gt;&lt;u&gt;USAGE&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are not many examples that uses SecureString class so I'll try to show you where this class is used in the framework class library by developing a small application that uses secure string. To avoid complications our sample application will be a small (micro) console application that stores passwords in secure string and renders it to console. Let's start with knowing about FCL usage of SecureString class,&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Framework Class Library usage&lt;/strong&gt; 

    &lt;ul&gt;
      &lt;li&gt;&lt;u&gt;System.Diagnostics&lt;/u&gt; 

        &lt;ul&gt;
          &lt;li&gt;&lt;font color="#404040"&gt;System.Diagnostics.Eventing.Reader.EventLogSession..ctor(String, String, String, SecureString, SessionAuthentication) &lt;strong&gt;&lt;em&gt;&lt;font color="#800000"&gt;[.ctor=constructor in IL]&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Diagnostics.Process.Start(String, String, SecureString, String) : Process &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Diagnostics.Process.Start(String, String, String, SecureString, String) : Process &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Diagnostics.ProcessStartInfo.Password : SecureString&lt;/font&gt; &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;

      &lt;li&gt;&lt;u&gt;System.Runtime.InteropServices&lt;/u&gt; 

        &lt;ul&gt;
          &lt;li&gt;&lt;font color="#404040"&gt;System.Runtime.InteropServices.Marshal.SecureStringToBSTR(SecureString) : IntPtr &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Runtime.InteropServices.Marshal.SecureStringToCoTaskMemAnsi(SecureString) : IntPtr &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Runtime.InteropServices.Marshal.SecureStringToCoTaskMemUnicode(SecureString) : IntPtr &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocAnsi(SecureString) : IntPtr &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocUnicode(SecureString) : IntPtr&lt;/font&gt; &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;

      &lt;li&gt;&lt;u&gt;System.Security.Cryptography&lt;/u&gt; 

        &lt;ul&gt;
          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.CspParameters..ctor(Int32, String, String, CryptoKeySecurity, SecureString) &lt;strong&gt;&lt;em&gt;&lt;font color="#800000"&gt;[CSP = Crypto Service Providers]&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.CspParameters.KeyPassword : SecureString &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[], SecureString) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[], SecureString, X509KeyStorageFlags) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String, SecureString) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String, SecureString, X509KeyStorageFlags) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate.Export(X509ContentType, SecureString) : Byte[] &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate.Import(Byte[], SecureString, X509KeyStorageFlags) : Void &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate.Import(String, SecureString, X509KeyStorageFlags) : Void &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[], SecureString) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[], SecureString, X509KeyStorageFlags) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String, SecureString) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String, SecureString, X509KeyStorageFlags) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2.Import(Byte[], SecureString, X509KeyStorageFlags) : Void &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Security.Cryptography.X509Certificates.X509Certificate2.Import(String, SecureString, X509KeyStorageFlags) : Void&lt;/font&gt; &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;

      &lt;li&gt;&lt;u&gt;System.Windows.Controls&lt;/u&gt; 

        &lt;ul&gt;
          &lt;li&gt;&lt;font color="#404040"&gt;System.Windows.Controls.PasswordBox.SecurePassword : SecureString &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Windows.Controls.PasswordBox.SetSecurePassword(SecureString) : Void &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Windows.Controls.PasswordTextContainer..ctor(PasswordBox) &lt;/font&gt;&lt;/li&gt;

          &lt;li&gt;&lt;font color="#404040"&gt;System.Windows.Controls.PasswordTextContainer.SetPassword(SecureString) : Void&lt;/font&gt; &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;Below I've added what's probably the most exhaustive list of SecureString usage you will ever find on web. Some of these uses secure string internally and some of them are not public. You will find a list of places where SecureString is used, places where SecureString objects are exposed, where SecureString objects are initialised and assemblies on which SecureString depends.&lt;/p&gt;

  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/InitBy.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="InitBy" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/InitBy_thumb.png" width="700" height="550" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/usedBy_1.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="usedBy" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/usedBy_thumb_1.png" width="702" height="624" /&gt;&lt;/a&gt; &lt;/p&gt;

  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/dependsUpon_1.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="dependsUpon" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/dependsUpon_thumb_1.png" width="704" height="36" /&gt;&lt;/a&gt;&lt;/p&gt;

  &lt;p&gt;Now let's move to our sample application. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Sample application&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;li&gt;Create a C# console application. You can name it as you like. Our application is very simple. It takes a password string from user and renders it back to the console. &lt;/li&gt;

    &lt;li&gt;Our sample application will have two methods, one Main [entry point] and other to render secure string on standard output stream [console in our case] &lt;/li&gt;

    &lt;li&gt;Make sure you check unsafe usage from project build properties window. This will add &lt;strong&gt;'/unsafe'&lt;/strong&gt; switch during compilation. '/unsafe' compilation switch is required to compile any unsafe code. Important thing is that we don't need '/unsafe' switch to create secure string objects, this check is required to access secure string's unmanaged memory location using pointers. If you use &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/78f4aasd.aspx"&gt;CSC.EXE&lt;/a&gt; [C # compiler] from console you can use '/unsafe' switch to compile unsafe code. 

      &lt;br /&gt;

      &lt;br /&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="prjProperties" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/prjProperties_thumb.png" width="585" height="512" /&gt;&amp;#160; &lt;/li&gt;

    &lt;li&gt;Our class looks like this 
      &lt;br /&gt;

      &lt;div class="csharpcode"&gt;
        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Security; &lt;span class="rem"&gt;//required for SecureString&lt;/span&gt;&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Runtime.InteropServices; &lt;span class="rem"&gt;//required for SecureString&lt;/span&gt;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;#160;&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Gaurav.SecureStringSamples.ConsoleLoginSample&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;{&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (SecureString password = &lt;span class="kwrd"&gt;new&lt;/span&gt; SecureString())&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                ConsoleKeyInfo consoleKeyInfo; &lt;span class="rem"&gt;//used to read console keys&lt;/span&gt;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;                Console.Write(&lt;span class="str"&gt;&amp;quot;Please enter password: &amp;quot;&lt;/span&gt;);&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;                {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;                    consoleKeyInfo = Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (consoleKeyInfo.Key == ConsoleKey.Enter) &lt;span class="kwrd"&gt;break&lt;/span&gt;;&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;                    password.AppendChar(consoleKeyInfo.KeyChar);&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;                    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;                }&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;                Console.WriteLine();&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;                RenderSecureString(password);&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;                Console.Read();&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            }&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;            Console.WriteLine(&lt;span class="str"&gt;&amp;quot;done&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;            Console.Read();&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;        }&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;unsafe&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RenderSecureString(SecureString toBeDisplayedSecureStr)&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;        {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;            Char* charPtr = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;            {&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;                &lt;span class="rem"&gt;//cast int ptr to char ptr&lt;/span&gt;&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;                &lt;span class="rem"&gt;//copy content from secure string to block of unmanaged memory&lt;/span&gt;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;                charPtr = (Char*)Marshal.SecureStringToCoTaskMemUnicode(toBeDisplayedSecureStr);&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;                &lt;span class="kwrd"&gt;for&lt;/span&gt; (Int32 count = 0; count &amp;lt; toBeDisplayedSecureStr.Length; count++) Console.Write(charPtr[count]);&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;            }&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;            &lt;span class="kwrd"&gt;finally&lt;/span&gt;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;            {&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;                &lt;span class="rem"&gt;//frees unmanaged string pointer allocated by Marshal.SecureStringToCoTaskMemUnicode&lt;/span&gt;&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (charPtr != &lt;span class="kwrd"&gt;null&lt;/span&gt;) Marshal.ZeroFreeCoTaskMemUnicode((IntPtr)charPtr);&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;            }&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;        }&lt;/pre&gt;

        &lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;    }&lt;/pre&gt;

        &lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;}&lt;br /&gt;&amp;#160;&lt;/pre&gt;
      &lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;li&gt;Output window will look something like this 
      &lt;br /&gt;

      &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/outputOne.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="outputOne" src="http://blogs.msdn.com/blogfiles/cisg/WindowsLiveWriter/SecureStringsin.NET_12719/outputOne_thumb.png" width="599" height="304" /&gt;&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cool, we have now created our very first secure string example. Next time I'll add some performance tests to this example and compare them with the standard string class. &lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Stay tuned!&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8991503" width="1" height="1"&gt;</description></item></channel></rss>
