<?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>Decrypt my World : DPAPI</title><link>http://blogs.msdn.com/alejacma/archive/tags/DPAPI/default.aspx</link><description>Tags: DPAPI</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>DpapiProtectedConfigurationProvider fails while decrypting web.config (ASP.NET)</title><link>http://blogs.msdn.com/alejacma/archive/2008/04/21/dpapiprotectedconfigurationprovider-may-fail-with-the-system-cannot-find-the-file-specified-error.aspx</link><pubDate>Mon, 21 Apr 2008 17:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8414651</guid><dc:creator>alejacma</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8414651.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8414651</wfw:commentRss><description>&lt;P&gt;Hi, welcome back,&lt;/P&gt;
&lt;P&gt;The other day we&amp;nbsp;faced a very similar issue to the one I commented on this post: &lt;A class="" href="http://blogs.msdn.com/alejacma/archive/2007/12/03/rsacryptoserviceprovider-fails-when-used-with-asp-net.aspx" mce_href="http://blogs.msdn.com/alejacma/archive/2007/12/03/rsacryptoserviceprovider-fails-when-used-with-asp-net.aspx"&gt;RSACryptoServiceProvider fails when used with ASP.NET&lt;/A&gt;. We were getting a very similar exception:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;"System.Configuration.ConfigurationErrorsException: Failed to decrypt using provider 'MyProtectedConfigurationProvider'. Error message from the provider: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;But this time we got it while &lt;STRONG&gt;System.Configuration.DpapiProtectedConfigurationProvider&lt;/STRONG&gt; was trying to &lt;STRONG&gt;decrypt&lt;/STRONG&gt; a &lt;STRONG&gt;protected configuration&lt;/STRONG&gt; section of our &lt;STRONG&gt;web.config&lt;/STRONG&gt; file. This provider was configured to work with &lt;STRONG&gt;user-level key storage &lt;/STRONG&gt;(&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.configuration.dpapiprotectedconfigurationprovider.usemachineprotection.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.configuration.dpapiprotectedconfigurationprovider.usemachineprotection.aspx"&gt;DpapiProtectedConfigurationProvider&lt;SPAN class=nu&gt;.&lt;/SPAN&gt;UseMachineProtection&lt;/A&gt; set to False) but the &lt;STRONG&gt;user profile&lt;/STRONG&gt; was not loaded.&lt;/P&gt;
&lt;P mce_keep="true"&gt;"The system cannot find the file specified" is a very typical error that appears when we can't access the private key we need to decrypt information, as those keys are usually stored in files in the user profile.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Additionally, if DPAPI works with user-level key storage, it requires the user profile to be loaded in order to store i.e. the master key it uses (see &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms995355.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms995355.aspx"&gt;Windows Data Protection&lt;/A&gt; for details on this).&lt;/P&gt;
&lt;P mce_keep="true"&gt;As we saw already (check &lt;A class="" href="http://blogs.msdn.com/alejacma/archive/2007/12/03/rsacryptoserviceprovider-fails-when-used-with-asp-net.aspx" mce_href="http://blogs.msdn.com/alejacma/archive/2007/12/03/rsacryptoserviceprovider-fails-when-used-with-asp-net.aspx"&gt;previous RSACryptoServiceProvider post&lt;/A&gt; for details), neither IIS nor ASP.NET will load the profile automatically. We may be able to load it by calling &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/bb762281(VS.85).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb762281(VS.85).aspx"&gt;LoadUserProfile&lt;/A&gt; API or by using a &lt;STRONG&gt;dummy Windows Service&lt;/STRONG&gt; (and Service Control Manager -SCM-&amp;nbsp;will load the profile on our behalf). If this doesn't work for us, we will have to use &lt;STRONG&gt;machine-level key storage&lt;/STRONG&gt; instead.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8414651" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/DPAPI/default.aspx">DPAPI</category></item></channel></rss>