Encrypt only passwords in web.config ASP.NET

How can I encrypt only passwords in the web.config file?

<add name="PSystem" connectionString="Server=test;Database=Dev;User ID=testuser;Password=password@123;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
+3
source share
3 answers

I believe that built-in encryption mechanisms work throughout the connectionString section:

See this site for more details.

If you want to encrypt passwords in memory that can be entered by the user through the login form, you can use SecureString

+2
source

you can try using flags in the connection string as follows:

<add name="PSystem" 
 connectionString="Server=test;
                   Database=Dev;
                   User ID=@UserID@;
                   Password=#Password#;
                   Trusted_Connection=False;
                   Encrypt=True;" 
  providerName="System.Data.SqlClient" />

then you can encrypt the user and password as follows:

<add key="DB_User" value = [Encrypted Username]>
<add key="DB_Password" value = [Encrypted Password]>

Then in the code, you simply replace the flags:

string _connectionString = ConfigurationManager.ConnectionStrings["PSystem"].ConnectionString;

string user = Decrypt(ConfigurationManager.AppSettings["DB_User"]);
string password = Decrypt(ConfigurationManager.AppSettings["DB_Password"]);

_connectionString = _connectionString.Replace("##User##", user).Replace("##Password##", password);
+1
source

, Aspnet_regiis.exe -pe , .

aspnet_regiis -pe "connectionStrings" -app "/ SampleApplication" -prov "RsaProtectedConfigurationProvider"

Source: http://msdn.microsoft.com/en-us/library/zhhddkxy(v=vs.100).aspx

+1
source

All Articles