diff --git a/Modules.Database/Adapters/MSSQLServer.vb b/Modules.Database/Adapters/MSSQLServer.vb index a105e174..da5bca1b 100644 --- a/Modules.Database/Adapters/MSSQLServer.vb +++ b/Modules.Database/Adapters/MSSQLServer.vb @@ -1,6 +1,7 @@ Imports System.ComponentModel Imports System.Data.Common Imports System.Data.SqlClient +Imports DigitalData.Modules.Encryption Imports DigitalData.Modules.Logging Public Class MSSQLServer @@ -52,6 +53,34 @@ Public Class MSSQLServer End Try End Sub + ''' + ''' Encrypts a connection string password. + ''' + ''' A connection string with a plain-text password + ''' The connection string with the password encrypted. + Public Shared Function EncryptConnectionString(ConnectionString As String) As String + Dim oEncryption As New EncryptionLegacy() + Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString} + Dim oEncryptedPassword = oEncryption.EncryptData(oBuilder.Password) + oBuilder.Password = oEncryptedPassword + + Return oBuilder.ToString() + End Function + + ''' + ''' Decrypts a connection string password. + ''' + ''' A connection string with a encrypted password + ''' The connection string with the password decrypted. + Public Shared Function DecryptConnectionString(ConnectionString As String) As String + Dim oEncryption As New EncryptionLegacy() + Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString} + Dim oDecryptedPassword = oEncryption.DecryptData(oBuilder.Password) + oBuilder.Password = oDecryptedPassword + + Return oBuilder.ToString() + End Function + Public Function GetConnectionString(Server As String, Database As String, UserId As String, Password As String) As String Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With { .DataSource = Server, diff --git a/Modules.Database/Database.vbproj b/Modules.Database/Database.vbproj index 045a799c..d8b0b982 100644 --- a/Modules.Database/Database.vbproj +++ b/Modules.Database/Database.vbproj @@ -139,6 +139,10 @@ + + {8a8f20fc-c46e-41ac-bee7-218366cfff99} + Encryption + {903b2d7d-3b80-4be9-8713-7447b704e1b0} Logging