5

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?

theB
  • 6,450
  • 1
  • 28
  • 38
zex_rectooor
  • 692
  • 7
  • 26
  • can you post the code how you are encrypting? – Krsna Kishore Oct 26 '15 at 12:05
  • I used [this article](http://www.codeproject.com/Tips/598863/EncryptionplusDecryptionplusConnectionplusStringpl) to encrypt, it has program to encrypt config file – zex_rectooor Oct 26 '15 at 12:09
  • ah got it, There is [this](http://www.codeproject.com/Tips/795135/Encrypt-ConnectionString-in-Web-Config) article which i Implemented for encrypting and it takes care of encrytion and whicle coming to decryption asp.net will handle it automatically.so you dont need to worry about the decryption – Krsna Kishore Oct 26 '15 at 12:35
  • I need to encrypt in `app.config` not `web.config`. anyway, i tried this article and windows shows _can not be opened_ error in cmd – zex_rectooor Oct 26 '15 at 12:45
  • did you used vs cmd ?in administrator mode> – Krsna Kishore Oct 26 '15 at 12:47
  • for app config also this method works here is a [link](http://stackoverflow.com/questions/11637348/encrypt-connection-string-in-app-config/29177724#29177724) supports my statement – Krsna Kishore Oct 26 '15 at 12:52
  • Yes, i tried in administrator mode but still same error, could not open file.failed – zex_rectooor Oct 26 '15 at 12:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93362/discussion-between-webruster-and-zex-rectooor). – Krsna Kishore Oct 26 '15 at 12:55

1 Answers1

4

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.

Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48
  • 2
    But `aspnet_regiis` use DPAPI as "local key" i.a. will only work on that specific computer and only on Windows computers. – MrCalvin Aug 01 '19 at 10:42
  • @MrCalvin at the time of writing this answer , my intention was to support for windows , i haven't mentioned anywhere that would support to other systems, if i said that phrase then you can oppose me . any ways thanks for pointing out . – Krsna Kishore Aug 05 '19 at 09:08
  • 2
    But it wouldn't even work for Windows, it only works for one and current Windows computer, not on "..different systems..." as stated in the header of the question. – MrCalvin Aug 05 '19 at 14:13
  • @MrCalvin , yes that one system would be your windows server and if you want to use on multiple computer write a powershell script and execute them as your need basis – Krsna Kishore Aug 07 '19 at 12:39