Save connection string savely in C#

时间:2018-12-03 13:16:19

标签: c# wpf encryption

I have an C# WPF programm written in C# with Visual Studio. In it there's an SQL Connect Class, which gets the ConnectionString from a config file:

ConnectionStringSettingsCollection SQLString =
        ConfigurationManager.ConnectionStrings;
        string connectionString = "";

        if (SQLString != null)
        {
            foreach (ConnectionStringSettings cs in SQLString)
            {
                connectionString = cs.ConnectionString;
            }
        }

        connection = new MySqlConnection(connectionString);

The Connection string is in a seperate config:

  <connectionStrings>
<add name="SQLServer"
 providerName="System.Data.ProviderName"
 connectionString="SERVER=my.domain;DATABASE=myDB;UID=myUser;PASSWORD=myPassword;" />

As far as I understand it, you shouldn't put passwords into the compiled code. I've hear that you can encrypt config files. How can I do this? Could someone provide a step by step example?

Thanks!

0 个答案:

没有答案