<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Personal website of Dave Hope &#187; C#</title>
	<atom:link href="http://davehope.co.uk/Blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://davehope.co.uk</link>
	<description>Open source projects, sysadmin stuff and general geekage</description>
	<lastBuildDate>Tue, 18 May 2010 11:46:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Decrypting DPAPI (aspnet_setreg) stored credentials</title>
		<link>http://davehope.co.uk/Blog/decrypting-dpapi-aspnet_setreg-stored-credentials/</link>
		<comments>http://davehope.co.uk/Blog/decrypting-dpapi-aspnet_setreg-stored-credentials/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 17:01:09 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Microsoft .Net]]></category>

		<guid isPermaLink="false">http://davehope.co.uk/?p=85</guid>
		<description><![CDATA[I came across a problem at work where I needed to recover credentials that had been stored in the registry using .Net&#8217;s DPAPI (aspnet_setreg). Thankfully the open source NCrypto library came to the rescue. Here&#8217;s a simple bit of code making use of the NCrypto.Security.Cryptography assembly to decrypt the data: &#60;%@ Page Language="C#" Debug="true" %&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a problem at work where I needed to recover credentials that had been stored in the registry using .Net&#8217;s DPAPI (aspnet_setreg). Thankfully the <a href="http://ncrypto.sourceforge.net/default.htm">open source NCrypto library</a> came to the rescue.</p>
<p>Here&#8217;s a simple bit of code making use of the NCrypto.Security.Cryptography assembly to decrypt the data:</p>
<pre>&lt;%@ Page Language="C#" Debug="true" %&gt;
&lt;script language="C#" runat="Server"&gt;
protected void Page_Load(object sender, System.EventArgs e)
{
byte[] regUsername;
byte[] regPassword;
string strUsername;
string strPassword;
Microsoft.Win32.RegistryKey reg;

reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\NWtraders\Login\ASPNET_SETREG");

regUsername = (byte[])reg.GetValue("username");
regPassword = (byte[])reg.GetValue("password");

strUsername = Encoding.Unicode.GetString( NCrypto.Security.Cryptography.ProtectedData.Unprotect( regUsername ) );
strPassword = Encoding.Unicode.GetString( NCrypto.Security.Cryptography.ProtectedData.Unprotect( regPassword ) );

System.Web.HttpContext.Current.Response.Write( strUsername );
System.Web.HttpContext.Current.Response.Write( strPassword );
}
&lt;/script&gt;</pre>
<p>Throw the .dll in your bin folder or GAC and you&#8217;re good to go. Make sure you&#8217;ve got access to the relevant registry keys used though.</p>
]]></content:encoded>
			<wfw:commentRss>http://davehope.co.uk/Blog/decrypting-dpapi-aspnet_setreg-stored-credentials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
