I want to store a password in my app.config

Topics: Cryptography Application Block
Apr 21, 2010 at 11:19 PM

I'm migrating from 1.x E/L to 4.1 and I'm confused about how to use the crypto block to store an encrypted password as an appsetting key/value pair. My first attempt at using the EncryptSymmetric/DecryptSymmetric functions failed as soon as I tried to distribute my application and received the error "Key not valid for use in specified state". My key file is being distributed with my application, but my new understanding is that the key is only good for use of the same machine that it was created for.

In the original 1.x E/L implementation the entire dataconfiguration.config file was encrypted with what I see is described as a file/key algorithm.

So the put it simply, how to a include an encrypted password in my config file that can be decrypted in code, what's the best  / easiest way to do this ?





Apr 22, 2010 at 4:02 AM
Edited Dec 7, 2010 at 7:50 AM

Hi stoned99, the key file can be used in any machine.  To do this, you need to declare a new protected configuration provider in your config, use your own key container, export it and then import it to the machines where you want your app to run.  Do you only really need to encrypt the password?  Coz if not, you can try out this approach which encrypts the whole connectionstring: http://msdn.microsoft.com/en-us/library/ms998283.aspx#paght000006_webfarmscenarios


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.