C # How to encrypt SQL Server connection string?

I want to create a client that connects to SQL Server and has full access.

How to do this so that others do not see the connection string for SQL Server and do not access it through other db editors? I know that .NET applications can be decompiled, so I'm afraid for my server.

0
source share
3 answers

A publicly accessible client with full db rights is usually never a good idea, so you can rethink this.

Here is a good MSDN article citing your issue:

https://msdn.microsoft.com/en-us/library/89211k9b(v=vs.110).aspx

Azure, .

:

SecureString.

, SQL .

+1

/ .

, , Base64.

Unencoded Connection:

server=localhost\SQLEXPRESS2012;database=testdb;uid=testuser;pwd=supersecret

Base64:

c2VydmVyPWxvY2FsaG9zdFxTUUxFWFBSRVNTMjAxMjtkYXRhYmFzZT10ZXN0ZGI7dWlkPXRlc3R1c2VyO3B3ZD1zdXBlcnNlY3JldA==

App.config .

<add name="TestDb" connectionString="c2VydmVyPWxvY2FsaG9zdFxTUUxFWFBSRVNTMjAxMjtkYXRhYmFzZT10ZXN0ZGI7dWlkPXRlc3R1c2VyO3B3ZD1zdXBlcnNlY3JldA==" providerName="System.Data.SqlClient" />

, DbContext, , .

using System;
using System.Configuration;
using System.Data.Common;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Text;

namespace TestApp
{
    public class TestDb : DbContext
    {
        public TestDb() : base(CreateConnection("TestDb"), true)
        {
        }

        static DbConnection CreateConnection(string dbName)
        {
            string encodedCs = ConfigurationManager.ConnectionStrings[dbName].ConnectionString;
            string decodedCs = Encoding.UTF8.GetString(Convert.FromBase64String(encodedCs));
            return new SqlConnection(decodedCs);
        }
    }
}

, Base64, , , .

0

All Articles