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 t开发者_运维知识库he 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?
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.
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.
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.
精彩评论