Solved

(Discussion)How to secure the password of my database in my connection string?

Posted on 2006-10-26
6
261 Views
Last Modified: 2010-04-23
Everybodies comment is welcome... Please don't hesitate to give your Ideas...

How can I secure the password of my database in my connection string?

Here is my connection string...

"'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Resources\dbRoomReservation.mdb;Persist Security Info=True;Jet OLEDB:Database Password=a"

I am using vb 2005 express...

Thanks in Advance.
{Jack}
0
Comment
Question by:JackOfPH
6 Comments
 
LVL 9

Assisted Solution

by:DjDezmond
DjDezmond earned 150 total points
ID: 17809960
You could encrypt and then store the whole connection string in the registry somewhere, and call it 'on-the-fly' decrypting it on the way...?

http://www.codeproject.com/dotnet/EnterpriseConectionString.asp
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17810141
Thanks for the input...

The method used above is nice especially if you are using sql server...
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17810149
Is there any more Ideas?
I am looking for any different ways in securing connection strings.
So, your comments are still welcome...

{Jack}
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Accepted Solution

by:
escheider earned 200 total points
ID: 17810624
I encrypt and decrypt querystring variables in ASP.NET applications when the values hold sensitive information or information I don't want easily available.   I use an encrypt and decrypt function and pass the values to these functions whenever I interact with them.  You could do the same with your connection string password:


Public Class clsSecurity

    Private key() As Byte = {}
    Private IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
    Private sEncryptionKey As String = "12345678"  '64 bit key

#Region "Cryptography Section"
    Public Function Decrypt(ByVal stringToDecrypt As String) As String

        If Len(stringToDecrypt) > 0 Then
            Dim inputByteArray(stringToDecrypt.Length) As Byte
            Try
                key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))
                Dim des As New DESCryptoServiceProvider
                inputByteArray = Convert.FromBase64String(stringToDecrypt)
                Dim ms As New MemoryStream
                Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), _
                    CryptoStreamMode.Write)
                cs.Write(inputByteArray, 0, inputByteArray.Length)
                cs.FlushFinalBlock()
                Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
                Return IsNull(encoding.GetString(ms.ToArray()), "")
            Catch e As Exception
                Return e.Message
            End Try
        Else
            Return 0
        End If
    End Function

    Public Function Encrypt(ByVal stringToEncrypt As String) As String
        Try
            key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))
            Dim des As New DESCryptoServiceProvider
            Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes( _
                stringToEncrypt)
            Dim ms As New MemoryStream
            Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), _
                CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Return Convert.ToBase64String(ms.ToArray())
        Catch e As Exception
            Return e.Message
        End Try
    End Function
#End Region

End Class



0
 
LVL 18

Assisted Solution

by:DarrenD
DarrenD earned 150 total points
ID: 17810660
Hi,

Well the idea to encrypt the connection string / password is definitely the first step.

Personally I don't like the registry so I don't use it much. I prefer to use an XML file to store the encrypted string. When using .NET you could also just store the encrypted connection string in either an app.config file for a web.config file or even create your own config file.

I usually encrypt the entire connection string as opposed to the just the password but thats just me.

Hope this helped a little.

Darren
0
 
LVL 15

Author Comment

by:JackOfPH
ID: 17816229
Thank you very much...

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now