tags:

views:

25

answers:

3

Hi there. I have created an applicaton that requires the 2 connection strings in the app.config and some appSettings to be encrypted.

I saved my app.config as web.config and run the asp.net aspnet_regiis -pe command for both "connectionStrings" and "appSettings"

The encryption works and I can run it on my local dev box however when I try moving it on a fresh machine it fails.

Is there extra steps I need to be doing in my application to use the encrypted settings?

+3  A: 

You need to run the aspnet_regiis -pe command on the target machine to encrypt the configuration file. The application works on the local machine because you ran the command on this machine.

Darin Dimitrov
What if I dont have access on the client machine? I have built a application and packaged it up. I want the end user to be able to run the setup themselves.
You need to obtain the server keys. Take a look at [this article](http://msdn.microsoft.com/en-us/library/ms998283.aspx#paght000006_webfarmscenarios).
Darin Dimitrov
A: 

The way we do this in our environment is to have the config in the clear in the MSI (it's tokenised and is only fully written at install time) and then we have custom actions to do the "aspnet_regiis -pe" activity (done through the framework and not using the command line though).

If you don't have access to the end machine then you won't be able to encrypt usefully, you will always end up giving away the private key to allow the strings to be decrypted - and then you are just doing security through obscurity which doesn't work.

Alan Mullett
Ok so just so I understand correctly. (in my case I am using installsheild) I would package up the application without any encryption, during the install I would create a custom action that calls "aspnet_regiis -pe" ? is that right?
yes, other than I wouldn't shell out and call aspnet_regiis, have a look at this http://stackoverflow.com/questions/21965/programmatically-encrypting-a-config-file-in-net which will help do it through the framework api.
Alan Mullett
A: 

aspnet_regiis -pe stores the encryption key using the data protection API (aka DPAPI), which is machine-specific. By default, it stores the encryption key in the machine store rather than user store. (e.g. You don't need to run aspnet_regiis as the user that will be running the web app, only on the same box.) You need to run the command on the destination box so that the encryption key is properly stored in DPAPI. You can find more information here:

http://msdn.microsoft.com/en-us/library/zhhddkxy.aspx

If you're going to be running in a web farm scenario, you might want to use the same encrypted configuration section on all machines. Thus you need to share encryption keys across machines. The same article above links to RsaProtectedConfigurationProvider and information on sharing keys across machines.

James Kovacs