Database: Add Encryption methods for connection string
This commit is contained in:
parent
aa6e211957
commit
258d412b9a
@ -1,6 +1,7 @@
|
|||||||
Imports System.ComponentModel
|
Imports System.ComponentModel
|
||||||
Imports System.Data.Common
|
Imports System.Data.Common
|
||||||
Imports System.Data.SqlClient
|
Imports System.Data.SqlClient
|
||||||
|
Imports DigitalData.Modules.Encryption
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
Public Class MSSQLServer
|
Public Class MSSQLServer
|
||||||
@ -52,6 +53,34 @@ Public Class MSSQLServer
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Encrypts a connection string password.
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="ConnectionString">A connection string with a plain-text password</param>
|
||||||
|
''' <returns>The connection string with the password encrypted.</returns>
|
||||||
|
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
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Decrypts a connection string password.
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="ConnectionString">A connection string with a encrypted password</param>
|
||||||
|
''' <returns>The connection string with the password decrypted.</returns>
|
||||||
|
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
|
Public Function GetConnectionString(Server As String, Database As String, UserId As String, Password As String) As String
|
||||||
Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With {
|
Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With {
|
||||||
.DataSource = Server,
|
.DataSource = Server,
|
||||||
|
|||||||
@ -139,6 +139,10 @@
|
|||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Encryption\Encryption.vbproj">
|
||||||
|
<Project>{8a8f20fc-c46e-41ac-bee7-218366cfff99}</Project>
|
||||||
|
<Name>Encryption</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
||||||
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
||||||
<Name>Logging</Name>
|
<Name>Logging</Name>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user