Reputation: 22661
We are getting the following error (in asp.net website) when applied encryption.
Parser Error Message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.
Note: Please see the steps listed below that we followed. (We have granted ACL permission for NT Authority\Network Service on NetFrameworkConfigurationKey)
Note: We are using Windows Authentication Enabled and ASP.NET impersonation Enabled in IIS7. It is running in Windows Server 2008. The access is controlled based on whether a user is part of allowed AD group (which will be listed in config file).
The interesting part is that this error happens when users of group1 (from location1) access it. When users of group2 (from locatiob2) try to access it, the error does not come.
Any thoughts on how to correct it?
We have followed the steps listed below from our deployment document.
• Verify that defaultProvider="RsaProtectedConfigurationProvider"
• Verify that keyContainerName="NetFrameworkConfigurationKey"
Note: Default location for machine.config is C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Config
Upvotes: 7
Views: 40974
Reputation: 2830
In my case, I had made my connection strings encrypted using ASPNET_REGIIS. I had one last application I finally got around to modifying to move from an older server to this server where encryption key was used. There was an older version of this application deployed already but not used. When I deployed (Published) the latest version to the server, I used the Replace method instead of delete. I came across this error, and stumbled here. None of the solutions worked for me.
My Fix: so I decided to clear the contents of the application folder, and re-publish.
Doing so corrected my issue.
Upvotes: 0
Reputation: 22661
Following is an approach I tried which does not involve Machine config.
Note: If the destination is in Windows Sever 2008, the encryption steps need to be executed in a Windows Server 2008 itself.
Executed the below codes in server A
Note:- Registering key
cd C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
aspnet_regiis.exe -pc "MyProjectKeys" -exp
Note:- GRANTING ACCESS on SERVER A only
aspnet_regiis.exe -pa "MyProjectKeys" "IIS APPPOOL\testpsreloservices"
aspnet_regiis.exe -pa "MyProjectKeys" "NT AUTHORITY\NETWORK"
Exported XML file containing RSA Key
aspnet_regiis.exe -px "MyProjectKeys" E:\wmapps\webroot\myservice\MyProjectKey.xml –pri
Added the following in web.config
<configProtectedData>
<providers>
<clear/>
<remove name="RSAProtectedConfigurationProvider" />
<add name="RSAProtectedConfigurationProvider" keyContainerName="MyProjectKeys"
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,

Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
 processorArchitecture=MSIL"
useMachineContainer="true" />
</providers>
</configProtectedData>
Encrypted
aspnet_regiis -pef "connectionStrings" "E:\wmapps\webroot\myservice" -prov "RsaProtectedConfigurationProvider"
Copied the encrypted files in B Server. Copied the key xml file into the B Server.
Created batch file with the following commands and Executed (for Key registration and granting access)
c:
cd C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
aspnet_regiis.exe -pi "MyProjectKeys" E:\wmapps\webroot\myservice\MyProjectKey.xml
aspnet_regiis.exe -pa "MyProjectKeys" "IIS APPPOOL\testpsreloservices"
aspnet_regiis.exe -pa "MyProjectKeys" "NT AUTHORITY\NETWORK"
Upvotes: 14
Reputation: 1383
If you have impersonation enabled, the RSA key container will be accessed using the identity of the user accessing the application---not Network Service.
You'll either need to disable impersonation, or add all the users that can access the application to the ACL of the key container.
Upvotes: 5