Compare commits
7 Commits
29daac2732
...
824f5cfc10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
824f5cfc10 | ||
|
|
33cfb257b1 | ||
|
|
3d30ab7309 | ||
|
|
5c9eb4bf1b | ||
|
|
258d412b9a | ||
|
|
aa6e211957 | ||
|
|
0e2ed68f9e |
@@ -5,6 +5,7 @@ Imports System.Data.SqlClient
|
||||
Public Class EncryptionLegacy
|
||||
Private TripleDes As New TripleDESCryptoServiceProvider
|
||||
Private DEFAULT_KEY As String = "!35452didalog="
|
||||
Private SALT_VALUE As String = "!Didalog35452Heuchelheim="
|
||||
|
||||
Sub New()
|
||||
TripleDes.Key = TruncateHash(DEFAULT_KEY, TripleDes.KeySize \ 8)
|
||||
@@ -31,53 +32,52 @@ Public Class EncryptionLegacy
|
||||
End Function
|
||||
|
||||
Public Function EncryptData(ByVal plaintext As String) As String
|
||||
Try
|
||||
' Convert the plaintext string to a byte array.
|
||||
Dim plaintextBytes() As Byte =
|
||||
System.Text.Encoding.Unicode.GetBytes(SALT_VALUE & plaintext)
|
||||
|
||||
' Convert the plaintext string to a byte array.
|
||||
Dim plaintextBytes() As Byte =
|
||||
System.Text.Encoding.Unicode.GetBytes("!Didalog35452Heuchelheim=" & plaintext)
|
||||
' Create the stream.
|
||||
Dim ms As New System.IO.MemoryStream
|
||||
' Create the encoder to write to the stream.
|
||||
Dim encStream As New CryptoStream(ms,
|
||||
TripleDes.CreateEncryptor(),
|
||||
System.Security.Cryptography.CryptoStreamMode.Write)
|
||||
|
||||
' Create the stream.
|
||||
Dim ms As New System.IO.MemoryStream
|
||||
' Create the encoder to write to the stream.
|
||||
Dim encStream As New CryptoStream(ms,
|
||||
TripleDes.CreateEncryptor(),
|
||||
System.Security.Cryptography.CryptoStreamMode.Write)
|
||||
' Use the crypto stream to write the byte array to the stream.
|
||||
encStream.Write(plaintextBytes, 0, plaintextBytes.Length)
|
||||
encStream.FlushFinalBlock()
|
||||
|
||||
' Use the crypto stream to write the byte array to the stream.
|
||||
encStream.Write(plaintextBytes, 0, plaintextBytes.Length)
|
||||
encStream.FlushFinalBlock()
|
||||
|
||||
' Convert the encrypted stream to a printable string.
|
||||
Return Convert.ToBase64String(ms.ToArray)
|
||||
' Convert the encrypted stream to a printable string.
|
||||
Return Convert.ToBase64String(ms.ToArray)
|
||||
Catch ex As Exception
|
||||
Return plaintext
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Entschlüsselt die Zeichenfolge
|
||||
Public Function DecryptData(ByVal encryptedtext As String) As String
|
||||
' Convert the encrypted text string to a byte array.
|
||||
Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext)
|
||||
Public Function DecryptData(ByVal EncryptedText As String) As String
|
||||
Try
|
||||
' Convert the encrypted text string to a byte array.
|
||||
Dim oEncryptedBytes() As Byte = Convert.FromBase64String(EncryptedText)
|
||||
|
||||
' Create the stream.
|
||||
Dim ms As New System.IO.MemoryStream
|
||||
' Create the decoder to write to the stream.
|
||||
Dim decStream As New CryptoStream(ms,
|
||||
TripleDes.CreateDecryptor(),
|
||||
System.Security.Cryptography.CryptoStreamMode.Write)
|
||||
' Create the stream.
|
||||
Dim oMemoryStream As New System.IO.MemoryStream
|
||||
' Create the decoder to write to the stream.
|
||||
Dim oCryptoStream As New CryptoStream(oMemoryStream,
|
||||
TripleDes.CreateDecryptor(),
|
||||
System.Security.Cryptography.CryptoStreamMode.Write)
|
||||
|
||||
' Use the crypto stream to write the byte array to the stream.
|
||||
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
|
||||
decStream.FlushFinalBlock()
|
||||
Dim result = System.Text.Encoding.Unicode.GetString(ms.ToArray)
|
||||
result = result.Replace("!Didalog35452Heuchelheim=", "")
|
||||
' Convert the plaintext stream to a string.
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Public Function DecryptConnectionString(ConnectionString As String) As String
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oDecryptedPassword = DecryptData(oBuilder.Password)
|
||||
oBuilder.Password = oDecryptedPassword
|
||||
|
||||
Return oBuilder.ToString()
|
||||
' Use the crypto stream to write the byte array to the stream.
|
||||
oCryptoStream.Write(oEncryptedBytes, 0, oEncryptedBytes.Length)
|
||||
oCryptoStream.FlushFinalBlock()
|
||||
Dim oResult = System.Text.Encoding.Unicode.GetString(oMemoryStream.ToArray)
|
||||
oResult = oResult.Replace(SALT_VALUE, "")
|
||||
' Convert the plaintext stream to a string.
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
Return EncryptedText
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' indem Sie "*" wie unten gezeigt eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyVersion("1.1.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.1.0.0")>
|
||||
|
||||
@@ -74,7 +74,6 @@ Public Class frmMonitor
|
||||
Try
|
||||
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "Monitor")
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.UserAppDataPath, Application.StartupPath)
|
||||
ConfigManager.DecryptConnectionStrings()
|
||||
Init(LogConfig)
|
||||
|
||||
If ConfigManager.Config.ConnectionString = String.Empty Then
|
||||
@@ -82,6 +81,7 @@ Public Class frmMonitor
|
||||
If oSQLConfig.ShowDialog() = DialogResult.OK Then
|
||||
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
|
||||
ConfigManager.Save()
|
||||
Application.Restart()
|
||||
Else
|
||||
ShowErrorMessage("No Database configured. Application will close!")
|
||||
Application.Exit()
|
||||
@@ -89,7 +89,8 @@ Public Class frmMonitor
|
||||
End If
|
||||
End If
|
||||
|
||||
Database = New MSSQLServer(LogConfig, ConfigManager.Config.ConnectionString)
|
||||
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
|
||||
Database = New MSSQLServer(LogConfig, oConnectionString)
|
||||
GridBuilder = New GridBuilder(New List(Of GridView) From {GridView1, GridView2, GridView3, GridView4})
|
||||
GridBuilder.
|
||||
WithDefaults().
|
||||
@@ -133,7 +134,7 @@ Public Class frmMonitor
|
||||
|
||||
Private Function LoadGDPicture() As String
|
||||
Dim oSQL = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'"
|
||||
Return Database.GetScalarValue(oSQL).ToString()
|
||||
Return Database.GetScalarValue(oSQL)
|
||||
End Function
|
||||
|
||||
Private Sub buttonSearch_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles buttonSearch.ItemClick
|
||||
|
||||
@@ -116,12 +116,8 @@ Public Class ClassInit
|
||||
End Sub
|
||||
|
||||
Private Sub CheckConnectivity(MyApplication As My.MyApplication)
|
||||
Dim oCrypt As New EncryptionLegacy()
|
||||
Dim oBuilder = My.SystemConfig.GetConnectionStringBuilder(My.SystemConfig.ConnectionString)
|
||||
oBuilder.Password = oCrypt.DecryptData(oBuilder.Password)
|
||||
Dim oDecryptedConnectionString = oBuilder.ToString
|
||||
|
||||
My.Database = New MSSQLServer(My.LogConfig, oDecryptedConnectionString)
|
||||
Dim oConnectionString = MSSQLServer.DecryptConnectionString(My.SystemConfig.ConnectionString)
|
||||
My.Database = New MSSQLServer(My.LogConfig, oConnectionString)
|
||||
|
||||
If My.Database.DBInitialized = False Then
|
||||
_Logger.Warn("Could not initialize DD_ECM-Database!")
|
||||
|
||||
@@ -166,27 +166,6 @@ Public Class ConfigManager(Of T)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function DecryptConnectionStrings() As Boolean
|
||||
Try
|
||||
Dim oType As Type = GetType(T)
|
||||
Dim oProperties = oType.GetProperties()
|
||||
Dim oEncryption = New EncryptionLegacy()
|
||||
|
||||
For Each oProperty In oProperties
|
||||
If Attribute.IsDefined(oProperty, GetType(ConnectionStringAttribute)) Then
|
||||
Dim oValue = oProperty.GetValue(_Config, Nothing)
|
||||
Dim oDecryptedValue = oEncryption.DecryptConnectionString(oValue)
|
||||
oProperty.SetValue(_Config, oDecryptedValue, Nothing)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Copies all properties from Source to Target, except those who have an attribute
|
||||
''' listed in ExcludedAttributeTypes
|
||||
|
||||
@@ -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
|
||||
|
||||
''' <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
|
||||
Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With {
|
||||
.DataSource = Server,
|
||||
|
||||
@@ -139,6 +139,10 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Encryption\Encryption.vbproj">
|
||||
<Project>{8a8f20fc-c46e-41ac-bee7-218366cfff99}</Project>
|
||||
<Name>Encryption</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
|
||||
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
||||
<Name>Logging</Name>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.1.4.0")>
|
||||
<Assembly: AssemblyFileVersion("2.1.4.0")>
|
||||
<Assembly: AssemblyVersion("2.2.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.2.0.0")>
|
||||
|
||||
@@ -129,11 +129,8 @@ Public Class frmSQLConfig
|
||||
Dim oResult = MessageBox.Show(STRING_CONNECTION_SUCCESSFUL, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
|
||||
If oResult = DialogResult.Yes Then
|
||||
Dim oCrypt As New EncryptionLegacy()
|
||||
Dim oEncryptedPassword = oCrypt.EncryptData(txtPassword.Text)
|
||||
Dim oEncryptedConnectionString = $"Server={txtServerName.Text};Database={cmbDatabase.Text};User Id={txtUserName.Text};Password={oEncryptedPassword};"
|
||||
|
||||
ConnectionString = oEncryptedConnectionString
|
||||
Dim oPlainTextConnectionString = $"Server={txtServerName.Text};Database={cmbDatabase.Text};User Id={txtUserName.Text};Password={txtPassword.Text};"
|
||||
ConnectionString = MSSQLServer.EncryptConnectionString(oPlainTextConnectionString)
|
||||
Close()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
|
||||
Reference in New Issue
Block a user