Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt connection string in app.config so that it works on different system [duplicate]

Tags:

c#

encryption

I used this article to encrypt my app.config. The problem is that when I test this app on another computer and that system couldn't 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 connection string in app.config?

like image 343
zex_rectooor Avatar asked Oct 18 '22 23:10

zex_rectooor


1 Answers

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

  1. Rename app.config to web.config
  2. Open command prompt and type: %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "connectionSt rings" c:\folder containing your web.config (stop at folder level and don't put the trailling "\")
  3. rename web.config back to app.config

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

like image 63
Tummala Krishna Kishore Avatar answered Oct 21 '22 15:10

Tummala Krishna Kishore