Encrypt connection string in app.config to make it work on different systems

I used this article to encrypt mine app.config

. The problem is, when I test this application on another computer and this system cannot decrypt the connection string.

I also read this article on MSDN and note that

The connection string can only be decrypted on the computer on which it was encrypted.

Now, how can I encrypt the connection string in app.config

?

+3
c # encryption


source to share


1 answer


As you mentioned, you need a solution for appconfig. You can easily apply the same solution as web.config, you just need to rename your app.config to web.config, encrypt with the aspnet_regiis tool, and then rename it back to app.config.

  • Rename app.config to web.config
  • Open a command prompt and enter:% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ aspnet_regiis -pef "connectionSt rings" c: \ folder containing your web.config (stop at and do not trail "\").
  • rename web.config back to app.config


You can open it in notepad to view the encrypted file. In visualstudio, you will see a transcript of it. You can use your connection string in the same way as if it was not encrypted.

+2


source to share







All Articles