Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

How to encrypt my connection string ?

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 ?
SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaufmed
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.
Avatar of Varshini S
Varshini S

ASKER

kaufmed - It is the windows application.
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
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial