Mediator
Mediator

Reputation: 15378

How to encrypt config file ? desktop .NET

Please give me a working example. I have already created a topic, but I'm not there who are not helped How to encrypt app.config?. Or am I just not what is not understood. Once again, I beg you give 100% working example.

I need to encrypt connectString to access the DB mysql.

is an example http://www.c-sharpcorner.com/UploadFile/yougerthen/306132008064100AM/3.aspx. There are two ways the first I have an error. Second, I do not understand how to use

Do not write a lot of text, I do not understand very well. I'm Russian.

UPDATE: I decided to use http://msdn.microsoft.com/en-us/library/system.configuration.rsaprotectedconfigurationprovider.aspx.

But I have an error: "Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. The error message from the provider: The object already exists."

I Create App WPF. Append file app.config.

app.config body:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="myconnect"
            connectionString="myConnectString" />
    </connectionStrings>
</configuration>

What do I do next ?

Upvotes: 0

Views: 2646

Answers (2)

Simon
Simon

Reputation: 3285

Best practice is to do it manualy in your settings class: http://msdn.microsoft.com/en-us/library/system.configuration.rsaprotectedconfigurationprovider.aspx

Upvotes: 1

Lex Li
Lex Li

Reputation: 63298

Do this in your installer,

  1. rename app.config to web.config.
  2. Use ASP.NET way to encrypt the data you want to encrypt.
  3. Rename it back to what.exe.config.

Upvotes: 1

Related Questions