Solved

How to encrypt my connection string ?

Posted on 2014-10-06
6
273 Views
Last Modified: 2014-10-06
i am using c# windows application. I am maintaining connection string information in machine.config file. How to encrypt my connection string in machine.config file and how to decrypt during accessing the application ?
0
Comment
Question by:Varshini S
6 Comments
 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 250 total points
ID: 40364472
You can encrypt and de-crypt any config file by using the DataProtectionConfigurationProvider
see the demo here http://www.codeproject.com/Tips/598863/EncryptionplusDecryptionplusConnectionplusStringpl

just a side note, you shouldn't encrypt the machine.config, you should use an app.confg in your application and encrypt it. the machine.config is a machine level configuration file and should not be touched by a single app.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40364525
I concur with the above. Take advantage of IIS's ability to cascade configuration files. Place--if not already there--a top-level config file in your IIS application directory, and then put your connection strings there. You should rarely ever need to edit machine.config.
0
 

Author Comment

by:Varshini S
ID: 40364664
kaufmed - It is the windows application.
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!

 

Author Comment

by:Varshini S
ID: 40364668
Sammy: i have used the sample application but when i use the encrypted values in my app.config file in the run time it is showing exception

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsFormsApplication1.exe
0
 

Author Comment

by:Varshini S
ID: 40364678
Sammy:

My app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration  xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <!--<startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>-->

  <connectionStrings>
      <clear/>
       <add name="DB2" connectionString="Data Source=SSA1\SQLEXPRESS2012;
    Initial Catalog=SAMPLE1;User ID=sa;Password=****" />


  </connectionStrings>
  


</configuration>

Open in new window


Encrypted key:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
        <EncryptedData>
            <CipherData>
                <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAGZ2bsBCKa0CfJWgESf/8pwQAAAACAAAAAAAQZgAAAAEAACAAAACPGC/IdWub2/OstAr43HQTRK8M90ds85G9/ZXCliVVPQAAAAAOgAAAAAIAACAAAABPyahInoV8/zMY7LxKpDR8hdE7xjzMqzZyw1sFjSfPWTAAAACrT/Jz+t/IdOgsJqEI2CE8xf0CsN8zgw7iZ0FMne2FTdJRn+8qIYkENxRtwy0LvhJAAAAA8f9QA+Y0Yh2/DlSFNKlJF51+gcN16sLjfqKV6UXXJtlzWPXztK3yhlVppq5cHkAHWe1JZy8852hjvVGQ3n0MSA==</CipherValue>
            </CipherData>
        </EncryptedData>
    </connectionStrings>
</configuration>

Open in new window

0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 40364986
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question