Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
At the moment I am storing my connection strings in my app.config file in plain text. Bad practice, I know, and I am trying to encrypt them instead. I've referred to https://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx and haven't had an issue with getting the app.config part working on my machine.

What I have tried:

My issue is when I come to use this on another machine. As the config file they are using has come from my machine, only my machine can decrypt the connectionstrings.

I cannot see past this and come up with a solution that allows the users machine to encrypt the config file without having an unencrypted version on their machine first.

Is there a solution that allows the users to encrypt the file themselves?
Posted
Updated 6-Oct-16 6:40am
Comments
Rob Philpott 6-Oct-16 11:31am    
Not necessarily bad practice to my mind - unless you have credentials in there - do you?

How are you encrypting the connection string?

The way I do it is encrypt the string, and copy the encrypted version into the config file. Then, I have an assembly that I can distribute that knows how to decrypt it (it contains the encryption info). If you want to decrypt the encrypted string, you have to have include that assembly in your app, and follow some simple steps to decrypt the string.

Of course, if a programmer is using the assembly, they can always inspect the decrypted connection string in the process of using a SqlCommand object, so I 'm not sure there is any benefit to encrypting it unless it's simply to prevent non-programmers from seeing it in the config file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900