Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1342
  • Last Modified:

How to encrypt connection string?

I have a .net 3.5 winforms app and want to encrypt the connectionString.  I have renamed app.config to web.config so it can be used with aspnet_regiis.  I'm in the app root folder and running this command line:

C:\src\project1\myapp>aspnet_regiis -pef "connectionSrings" -app "myapp"

No matter how I change the command line, I always get the help output.  No errors.  The app doesn't have an IIS website and is a web application project.  Any suggestions?
0
brettr
Asked:
brettr
  • 11
  • 9
2 Solutions
 
David RobitailleAnalyst ProgrammerCommented:
try to put the local path of the website instead.
aspnet_regiis.exe -pef "connectionStrings" "C:\Inetpub\wwwroot\MySite"
 
here a ref:
http://www.4guysfromrolla.com/articles/021506-1.aspx
0
 
David RobitailleAnalyst ProgrammerCommented:
<$/>you could also try to move into the %WINDOWSDIR%\Microsoft.Net\Framework\version directory before running the command.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
brettrAuthor Commented:
Last suggestion worked.  It output a larger amount of help at first until I got the command line correct.  I'm guessing it's a newer version of aspnet_iisreg.exe.

This section created by the encryption is giving errors:

  <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"

//Error 1
The 'configProtectionProvider' attribute is not declared

//Error 2
The element 'connectionStrings' has invalid child element 'EncryptedData' in namespace 'http://www.w3.org/2001/04/xmlenc#'. List of possible elements expected: 'add, remove, clear'.

Do you know about those?  App seems to run ok.
0
 
David RobitailleAnalyst ProgrammerCommented:
try to add this at the end of the command, it will uses DPAPI to encrypt and decrypt data instead of RSA
 prov "DataProtectionConfigurationProvider"

(you may have to restore your backup before doing it)
0
 
David RobitailleAnalyst ProgrammerCommented:
the switch char seem to be replaced, "" = "-"
it`s
-prov "DataProtectionConfigurationProvider"

0
 
brettrAuthor Commented:
Same problem just that now it looks like this:

 <connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
 ...
0
 
David RobitailleAnalyst ProgrammerCommented:
"This section created by the encryption is giving errors"

What program is giving those errors?

0
 
brettrAuthor Commented:
Adding this makes the errors go away:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
0
 
brettrAuthor Commented:
Unfortunately, that namespace also prevents my app from running.
0
 
David RobitailleAnalyst ProgrammerCommented:
???
What error message did you get?

did you run the aspnet_regiis.exe on the IIS Server. the encryption key is diferent than the one on your developement machine.
0
 
brettrAuthor Commented:
It complained that the app's configuration was invalid and to reinstall the app.
0
 
David RobitailleAnalyst ProgrammerCommented:
Who complained? ISS? visual studio?
0
 
brettrAuthor Commented:
I'm running the app in VS.NET.  I get the same error when double clicking the EXE.  It says the application configuration is incorrect.
0
 
David RobitailleAnalyst ProgrammerCommented:
???????????
How do you get an EXE from web application? And what are you doing with it?
Anyway this web.config encryption thing is supposed to work when you want to "deploy" a web application to a web server (usually IIS). the machine that will execute the program (the IIS server) must be the same that the one you used to encrypt the Web.config.
There must be something i dont understand about your setup, because i got no idea of what you are trying to do...
0
 
brettrAuthor Commented:
It is a winform app.  But that doesn't matter.  The point is that VS.NET complains about those particular attributes.

Yes - I found it that the machine which encyrpts the config needs to decrypt.  Not helpful.  How can you deploy this to other machines?
0
 
David RobitailleAnalyst ProgrammerCommented:
you cannot.
That thing is designed for ASP.NET web site not Winform app. You posted the question in "NET, C# Programming Language, Programming for ASP.NET" zones. dont you noticed the tool name is aspnet_regIIS???
but, now i understand the alusion about the app.config.
I think this link will be more helpfull
http://msdn.microsoft.com/en-us/library/ms998283.aspx 
 
0
 
brettrAuthor Commented:
I posted here because there is no such tool for winforms and using aspnet_regiis is the defacto standard to encrypt app.config files as well.
0
 
David RobitailleAnalyst ProgrammerCommented:
sorry, i keep the wrong link
http://www.codeproject.com/KB/cs/Configuration_File.aspx
if that cannot hlep, I sorry, but i connot help you futher, i diden`t do anything like this, my experience is of web.config and web app. I suggest you post a new question like
"How to encrypt connection string in app.config"
 
0
 
brettrAuthor Commented:
Thanks on the links you've been posting.  The programatic technique won't work since it has to encrypt/decrypt with each app run.  I only encrypt on app install.

Your help set me in the right direction.  I leave the app.config unencrypted in SVN.  During the win app MSI is install, it runs a batch file that renames app.config to web.config, encrypts it as above and renames it back to app.config.  viola!  It works fine.
0
 
David RobitailleAnalyst ProgrammerCommented:
I`m glad i gould help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now