473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Securing dB connection string in Web.config

Hi:

I'm storing my dB connection in web.config file. Since it will be easily
read by opening file, what is a good way to secure it?

Thanks,
Charlie
Nov 18 '05 #1
4 6726
The best technique is to use a trusted connection. That way you don't need
to list a username or password so there is nothing to hide.
If this is not possible, you can store the username and password encrypted
in the registry.
Here's more information:
http://msdn.microsoft.com/library/de...itysection.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"Charlie@CB FC" <ch*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi:

I'm storing my dB connection in web.config file. Since it will be easily
read by opening file, what is a good way to secure it?

Thanks,
Charlie

Nov 18 '05 #2
There is a good article on this in this month's edition of ASP.NET Pro. You
have to subscribe or buy the magazine though. The title of the article is
"Password in Web.config?"

http://www.aspnetpro.com/

-John Oakes
"Charlie@CB FC" <ch*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi:

I'm storing my dB connection in web.config file. Since it will be easily
read by opening file, what is a good way to secure it?

Thanks,
Charlie

Nov 18 '05 #3
First let me say, if you want real security, you will have to pay for it,
most of the low cost providers will let you have it but will charge you for
it. Otherwise you me need to find another provider. The same people that can
get at your web.config to read the password to your database will likely
already have access to your database with out your password. (Did that make
sense? It's so hard to tell)

That being said, I am in the same situation with my provider, so at the risk
of being chastised, here is what I have done: (I don't store any of this in
the Web.config, I use XML serialization to store it in it's own XML file)

I have a class that handles the database connection string, and it stores
the critical data (user name and password in an encrypted byte array) I have
overridden ToString() to give me the whole connection string when I ask for
it with the parts un-encrypted. Some thing like this:

public class DatabaseConnect ion
{
private byte[] _userid;
private byte[] _password;

public byte[] UserID
{
get { return _userid; }
set { _userid = value; }
}
public byte[] Password
{
get { return _password; }
set { _password = value; }
}
public string SetUserID(strin g user)
{
UserID = Globals.Encrypt (user);
}
private string GetUserID()
{
return Globals.Decrypt (_userid);
}
public string SetPassword(str ing pass)
{
Password = Globals.Encrypt (pass);
}
private string GetPassword()
{
return Globals.Decrypt (_password);
}
public override string ToString()
{
return string.Format(" user id={0}; password={1}; blah blah blah",
GetUserId(), GetPassword());
}
}

then Globals looks like this:

public class Globals
{
public static byte[] Encrypt(string s)
{
System.Text.ASC IIEncoding encoder = new System.Text.ASC IIEncoding();
return EncryptByteArra y(encoder.GetBy tes(s));
}

public static string Decrypt(byte[] b)
{
System.Text.ASC IIEncoding encoder = new System.Text.ASC IIEncoding();
byte[] result = DecryptByteArra y(b);
return encoder.GetStri ng(result);
}

// Encryption keys, fill in with byte values (0-255)
private static byte[] RC2Key = {0x0,0x0,0x0,0x 0,0xe0,0x0,0x0, 0x0}; //
<==Make up your own
private static byte[] RC2IV = {0x0,0x0,0x0,0x 0,0x0,0x0,0x0,0 x0}; //
<==Make up your own

private static byte[] EncryptByteArra y(byte[] value)
{
System.Security .Cryptography.R C2CryptoService Provider crypto = new
System.Security .Cryptography.R C2CryptoService Provider();
byte[] buffer;
System.Security .Cryptography.C ryptoStream clearTextStream ;
System.IO.Memor yStream cypherTextStrea m;

byte[] result;
buffer = value;

cypherTextStrea m = new System.IO.Memor yStream();
clearTextStream = new
System.Security .Cryptography.C ryptoStream(cyp herTextStream,
crypto.CreateEn cryptor(RC2Key, RC2IV),
System.Security .Cryptography.C ryptoStreamMode .Write);
clearTextStream .Write(buffer, 0, buffer.Length);
clearTextStream .FlushFinalBloc k();
result = cypherTextStrea m.ToArray();
return result;
}

private static byte[] DecryptByteArra y(byte[] value)
{
System.Security .Cryptography.R C2CryptoService Provider crypto = new
System.Security .Cryptography.R C2CryptoService Provider();
byte[] buffer;
System.Security .Cryptography.C ryptoStream cypherTextStrea m;
System.IO.Memor yStream clearTextStream ;
byte[] result;

buffer = value;
clearTextStream = new System.IO.Memor yStream();
cypherTextStrea m = new
System.Security .Cryptography.C ryptoStream(cle arTextStream,
crypto.CreateDe cryptor(RC2Key, RC2IV),
System.Security .Cryptography.C ryptoStreamMode .Write);
cypherTextStrea m.Write(buffer, 0, buffer.Length);
cypherTextStrea m.FlushFinalBlo ck();
result = clearTextStream .ToArray();
return result;
}

}
There it is, FWIW.

Brian W
As the risk of being chastized here it wat
"Charlie@CB FC" <ch*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi:

I'm storing my dB connection in web.config file. Since it will be easily
read by opening file, what is a good way to secure it?

Thanks,
Charlie

Nov 18 '05 #4
See my reply to "Using encrypted dB connection string" in this newsgroup
"Charlie@CB FC" <ch*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi:

I'm storing my dB connection in web.config file. Since it will be easily
read by opening file, what is a good way to secure it?

Thanks,
Charlie

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1805
by: Tyson Marchuk | last post by:
Hello, Background info Kind of new to using databases and I'm writing an app in C# which connects to a MySQL database. I was using the ODBC connector and a DSN entry to connect to the database but I've since found out that the ODBC connector has been bugged for some time and you can't send it numeric values (read floating point values) which basically makes it useless so I'm trying to switch to the MySQL .NET connector which I believe...
6
1777
by: Jon Davis | last post by:
I like the drag-and-drop accessibility of dragging a table to a Web Forms designer and seeing a SqlDataAdapter automatically created for me.. being able to create a DataSet from that is fun and exciting, because now with this schema based data outline Visual Studio provides me with a typed class for managing data complete with Intellisense menus exposing my own field names as C# object properties ... cool .. Anyway, I have a problem. I...
6
1504
by: Mike L. | last post by:
Hi, Pls, beware that I'm new to this :) I've developed several web appl, either with ASP or ASP.NET. All using SQL server as the back end. In my development environment, I have a single server running Win2K, which serves as Web Server and SQL server as well. And, since my hosting (production server) using the same config; ie: using a single server to serve both web server and SQL server; it's always been easy
19
2527
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet GetCategories() { SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial Catalog=XXXX;User ID=X;Password=Y");
14
3498
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that web.config file is protected by IIS and Windows security which is the case. And another argument is that...
2
1578
Frinavale
by: Frinavale | last post by:
Hello everyone! I'm having a problem securing my connection string. There are a lot of sites out there that explain how to secure a connection string in the Web.config or App.config file; however, my connection string is being used within a Class Library (implemented with VB.NET), which doesn't have these files. This class library is used by a web application to do all of my database manipulation so it is run under the ASPNET account....
2
6607
by: Thorsten Dittmar | last post by:
Hi, I don't get it. I'm using a typed dataset with table adapters and all that stuff. I have the database server running locally on my development system. Now: when creating a tableadapter I'm asked for the connection and the connection string is automatically stored in the settings. So far so good. However, my typed dataset is declared within a dll that implements other
9
6250
by: =?Utf-8?B?QW1tZXI=?= | last post by:
I've read many incomplete opinions about the "Best Practice" for securely accessing SQL but what I really need to find the "Best Practice" that fits my applications needs. Currently (alpha stage) I am Using a .Net DSN-Less SQLConnection method in my client program (vb.net) and sending uid/pwd across the network. The client only calls upon the stored procedures to access the tables in SQL 2005. This is a semi commercial application...
2
5391
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy ASP.NET applications that all manage connection strings in Web.config the same way, like this: This client has one Web.config file per application, and that one Web.config file is duplicated across all environments (i.e., dev machines, test,...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.