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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
kaufmed - It is the windows application.
ASKER
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.NullReferenceExcep tion' occurred in WindowsFormsApplication1.e xe
An unhandled exception of type 'System.NullReferenceExcep
ASKER
Sammy:
My app.config file
Encrypted key:
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>
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.