I am attempting to encrypt connection string values in the Web.Config file for an ASP.NET 2.0 web application, following the procedure described on MSDN. Using the RsaProtectedConfigurationProvider, I created and exported a machine-level key on my development machine (using the -pri flag), and imported the key and granted access on the web server. Prior to testing automatic decryption by ASP.NET, I wanted to try manually decrypting the Web.Config.
I am able to manually encrypt and decrypt the Web.Config on the same machine using the -pef and -pdf parameters respectively, but manually decrypting on the web server fails with a Bad Data
error message.
The oddest thing is that the keyContainerName attribute in my Web.Config file seems to be ignored. If I try replacing the correct value with gibberish (no longer corresponding to any key container I have created) the encryption and decryption still work on my development machine. Any ideas?
From your description, you're encountering some problems about encypting web.config via exportable RSA provider, correct?
According to the RSA encryption reference, I've performed some local tests, the normal process of encrypting web.config section via RSA provider and move to other machine is as below:
====================== Step 1
Create a machine-level RSA key container: aspnet_regiis -pc "MyTestKeys" -exp
Step 2
Grant Read Access to the RSA Encryption Key:
aspnet_regiis -pa "MyTestKeys" "NT AUTHORITY\NETWORK SERVICE"
Step 3
Encrypt the config file: aspnet_regiis -pef "connectionStrings" "physical path of the web site folder" -prov MyRSAProvider
export the container and import it back to other machine using the following steps
Step 4
Export the machine-level RSA key container: aspnet_regiis -px "MyTestKeys" "c:\Config-Key.xml" -pri
Step 5
Copy Config-Key.xml to c:\ on 2nd server
Step 6
Import the the machine-level RSA key container on the 2nd server: aspnet_regiis -pi "MyTestKeys" "c:\Config-Key.xml"
Step 7
Grant Read Access to the RSA Encryption Key: aspnet_regiis -pa "MyTestKeys" "NT AUTHORITY\NETWORK SERVICE"
Step 8
Copy encrypted web.config to 2nd server
========================
Based on the steps you mentioned, I think most of the process you've followed should be correct. So far I'd like to suggest you check the following things:
========encrypt config section=======
type="System.Configuration.RsaProtectedConfigurationProvider,System.Configur ation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
You can check them to see whether the problem is due to some of them.
Sincerely, Sanjay Manju suman
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With