Hallo,
in VB.Net wurde erfolgreich ein DataGridView UserControl erstellt.
Im Userform-Designer von Visual Studio 2015 werden die Benutzer-Properties korrekt angezeigt und können auch korrekt mit Inhalten im Designer.
Beim Ausführen der Anwendung werden allerdings immer die vorgenommenen Einstellungen im Designer durch die Standard-Einstellungen überschrieben.
Hat jemand einen Tip, wie die Fehlerursache eingegrenzt werden kann?
Ich habe eine Vermutung, dass es am Initialisieren des Controls liegt, bei dem die Standard-Einstellungen gesetzt werden.
Die Standardvorgaben werden nur an einer Stelle in der Cell-Klasse vorgegeben.
Hier der Code vom UserControl:
Klasse DataGridViewEncryptPasswordTextBoxCell:
Spoiler anzeigen
Klasse DataGridViewEncryptPasswordTextBoxColumn:
Spoiler anzeigen
Im Code wird zusätzlich auf eine Klasse TripleDES zugegriffen:
Spoiler anzeigen
in VB.Net wurde erfolgreich ein DataGridView UserControl erstellt.
Im Userform-Designer von Visual Studio 2015 werden die Benutzer-Properties korrekt angezeigt und können auch korrekt mit Inhalten im Designer.
Beim Ausführen der Anwendung werden allerdings immer die vorgenommenen Einstellungen im Designer durch die Standard-Einstellungen überschrieben.
Hat jemand einen Tip, wie die Fehlerursache eingegrenzt werden kann?
Ich habe eine Vermutung, dass es am Initialisieren des Controls liegt, bei dem die Standard-Einstellungen gesetzt werden.
Die Standardvorgaben werden nur an einer Stelle in der Cell-Klasse vorgegeben.
Hier der Code vom UserControl:
Klasse DataGridViewEncryptPasswordTextBoxCell:
VB.NET-Quellcode
- Option Explicit On
- Option Strict On
- Imports System.ComponentModel
- Public Class DataGridViewEncryptPasswordTextBoxCell
- Inherits System.Windows.Forms.DataGridViewTextBoxCell
- Private myTripleDES As New TripleDES
- Private _encryptPassword As Boolean
- Private _initVector As Byte()
- Private _passwordChar As Char
- Private _useSystemPasswordChar As Boolean
- Private editingControlPasswordChar As Char
- Private editingControlUseSystemPasswordChar As Boolean
- ' Button im Textbox rechts einblenden, wenn der Wert bearbeitet wird
- 'Private WithEvents _Button As ToggleButtonShowHidePassword
- Private WithEvents _Button As Button
- Private WithEvents _Textbox As TextBox
- Sub New()
- MyBase.New
- Me._encryptPassword = True
- Me._initVector = Nothing
- Me._passwordChar = CChar("")
- Me._useSystemPasswordChar = True
- End Sub
- <Description("Soll das eingegebene Passwort mit dem TripleDES-Verfahren verschlüsselt abgespeichert werden?")>
- <DefaultValue(True)>
- Public Property encryptPassword() As Boolean
- Get
- Return Me._encryptPassword
- End Get
- Set(value As Boolean)
- Me._encryptPassword = value
- End Set
- End Property
- <Description("InitVector muss 8 Bytes beinhalten, die durch Kommatas voneinander getrennt sind. Beispiel: 65, 110, 68, 26, 69, 178, 200, 219")>
- <DefaultValue("")>
- Public Property initVector As String
- Get
- If Me._initVector IsNot Nothing Then
- Return String.Join(",", Me._initVector)
- Else
- Return Nothing
- End If
- End Get
- Set(value As String)
- Dim IsValid As Boolean
- Dim myItems = myTripleDES.ConvertToBytes(value, 8, IsValid)
- If IsValid Then
- Me._initVector = myItems
- End If
- End Set
- End Property
- <Description("Passwort-Maskierungszeichen - Es kann nur ein Zeichen eingegeben werden!")>
- <DefaultValue("")>
- Public Property PasswordChar() As Char
- Get
- Return Me._passwordChar
- End Get
- Set(ByVal value As Char)
- Me._passwordChar = value
- End Set
- End Property
- <Description("Passwort maskiert anzeigen? True = Passwort wird maskiert angezeigt; False = Passwort wird in Klartext angezeigt")>
- <DefaultValue(True)>
- Public Property UseSystemPasswordChar() As Boolean
- Get
- Return Me._useSystemPasswordChar
- End Get
- Set(ByVal value As Boolean)
- Me._useSystemPasswordChar = value
- End Set
- End Property
- Public Overrides Function Clone() As Object
- Dim copy As DataGridViewEncryptPasswordTextBoxCell = DirectCast(MyBase.Clone(), DataGridViewEncryptPasswordTextBoxCell)
- copy.PasswordChar = Me._passwordChar
- copy.UseSystemPasswordChar = Me._useSystemPasswordChar
- copy.encryptPassword = Me._encryptPassword
- If Me._initVector IsNot Nothing Then
- copy.initVector = String.Join(",", Me._initVector)
- Else
- copy.initVector = ""
- End If
- Return copy
- End Function
- Protected Overrides Function GetFormattedValue(ByVal value As Object,
- ByVal rowIndex As Integer,
- ByRef cellStyle As System.Windows.Forms.DataGridViewCellStyle,
- ByVal valueTypeConverter As System.ComponentModel.TypeConverter,
- ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter,
- ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object
- Dim formattedValue As Object
- If Me._encryptPassword AndAlso value IsNot Nothing Then
- value = myTripleDES.DecryptText(CType(value, String), Me._initVector)
- End If
- If Me._useSystemPasswordChar AndAlso value IsNot Nothing Then
- 'Display the system password character in place of each actual character.
- 'TODO: Determine the actual system password character instead of hard-coding this value.
- formattedValue = New String(Convert.ToChar(&H25CF), CStr(value).Length)
- ElseIf Me._passwordChar <> Char.MinValue AndAlso value IsNot Nothing Then
- 'Display the user-defined password character in place of each actual character.
- formattedValue = New String(Me._passwordChar, CStr(value).Length)
- Else
- 'Display the value as is.
- formattedValue = MyBase.GetFormattedValue(value,
- rowIndex,
- cellStyle,
- valueTypeConverter,
- formattedValueTypeConverter,
- context)
- End If
- Return formattedValue
- End Function
- Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer,
- ByVal initialFormattedValue As Object,
- ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
- MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
- Dim _TextBox As TextBox = DirectCast(Me.DataGridView.EditingControl, TextBox)
- With _TextBox
- 'Remember the current password properties of the editing control.
- Me.editingControlPasswordChar = .PasswordChar
- Me.editingControlUseSystemPasswordChar = .UseSystemPasswordChar
- 'Set the new password properties of the editing control.
- .PasswordChar = Me._passwordChar
- .UseSystemPasswordChar = Me._useSystemPasswordChar
- ' Button rechts einblenden
- '_Button = New ToggleButtonShowHidePassword ' Button
- _Button = New Button
- _Button.Text = "..." ' ToDo: Umschalter für Sichtbar und unsichtbare Passwörter erstellen
- _Button.Dock = DockStyle.Right
- _Button.Cursor = Cursors.Hand
- _Button.Width = 20
- _Button.Visible = False
- .Controls.Add(_Button)
- AddHandler _TextBox.Enter, AddressOf Textbox_OnEnter
- 'AddHandler _TextBox.Enter, Function(sender, e) Textbox_OnEnter(myCell)
- AddHandler _TextBox.Leave, AddressOf Textbox_OnLeave
- End With
- End Sub
- ''' <summary>
- ''' Einblenden des Toggle-Buttons Show/Hide Password
- ''' </summary>
- ''' <param name="sender"></param>
- ''' <param name="e"></param>
- Protected Sub Textbox_OnEnter(sender As Object, e As EventArgs)
- 'Dim myTxtBx As TextBox = DirectCast(sender, TextBox)
- 'Dim myGridView As DataGridView = CType(myTxtBx.Parent.Parent, DataGridView)
- 'Dim myCell = myGridView.CurrentCell
- _Button.Visible = True
- End Sub
- ''' <summary>
- ''' Ausblenden des Toggle-Buttons Show/Hide Password
- ''' </summary>
- ''' <param name="sender"></param>
- ''' <param name="e"></param>
- Protected Sub Textbox_OnLeave(sender As Object, e As EventArgs)
- _Button.Visible = False
- End Sub
- ''' <summary>
- ''' Bei Bedarf wird der eingegebene Text vor einer Übernahme verschlüsselt
- ''' </summary>
- ''' <param name="rowIndex">Index im DataGridView</param>
- ''' <param name="Value">zu übernehmender Wert</param>
- ''' <returns>True oder False</returns>
- Protected Overrides Function SetValue(rowIndex As Integer, Value As Object) As Boolean
- If Me._encryptPassword AndAlso Value IsNot Nothing Then
- Value = myTripleDES.EncryptText(CType(Value, String), Me._initVector)
- End If
- Return MyBase.SetValue(rowIndex, Value)
- End Function
- Public Overrides Sub DetachEditingControl()
- MyBase.DetachEditingControl()
- With DirectCast(Me.DataGridView.EditingControl, TextBox)
- 'Reset the old password properties of the editing control.
- .PasswordChar = Me.editingControlPasswordChar
- .UseSystemPasswordChar = Me.editingControlUseSystemPasswordChar
- End With
- End Sub
- Private Sub _Button_Click(sender As Object, e As EventArgs) Handles _Button.Click
- 'Me.UseSystemPasswordChar = Not Me.UseSystemPasswordChar
- End Sub
- End Class
Klasse DataGridViewEncryptPasswordTextBoxColumn:
VB.NET-Quellcode
- Option Explicit On
- Option Strict On
- Imports System.ComponentModel
- Public Class DataGridViewEncryptPasswordTextBoxColumn
- Inherits System.Windows.Forms.DataGridViewColumn
- Private myTripleDES As New TripleDES
- Private _encryptPassword As Boolean
- Private _initVector As String = ""
- Private _passwordChar As Char
- Private _useSystemPasswordChar As Boolean
- <Category("Passwort")>
- Public Property PasswordChar() As Char
- Get
- Return Me._passwordChar
- End Get
- Set(ByVal value As Char)
- If Me._passwordChar <> value Then
- Me._passwordChar = value
- Dim cell As DataGridViewEncryptPasswordTextBoxCell = TryCast(Me.CellTemplate, DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- 'Update the template cell.
- cell.PasswordChar = value
- End If
- If Me.DataGridView IsNot Nothing Then
- 'Update each existing cell in the column.
- For Each row As DataGridViewRow In Me.DataGridView.Rows
- cell = TryCast(row.Cells(Me.Index), DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- cell.PasswordChar = value
- End If
- Next
- 'Force a repaint so the grid reflects the current property value.
- Me.DataGridView.Refresh()
- End If
- End If
- End Set
- End Property
- <Category("Passwort Verschlüsselung")>
- Public Property initVector As String
- Get
- If Me._initVector IsNot Nothing Then
- Return String.Join(",", Me._initVector)
- Else
- Return Nothing
- End If
- End Get
- Set(value As String)
- If value Is Nothing Then
- value = ""
- End If
- Dim IsValid As Boolean
- Dim myByte = myTripleDES.ConvertToBytes(value:=value, validCountItems:=8, IsValid:=IsValid)
- If IsValid Then
- If Not Me._initVector.Equals(value) Then
- Me._initVector = value
- Dim cell As DataGridViewEncryptPasswordTextBoxCell = TryCast(Me.CellTemplate, DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- 'Update the template cell.
- cell.initVector = value
- End If
- If Me.DataGridView IsNot Nothing Then
- 'Update each existing cell in the column.
- For Each row As DataGridViewRow In Me.DataGridView.Rows
- cell = TryCast(row.Cells(Me.Index), DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- cell.initVector = value
- End If
- Next
- 'Force a repaint so the grid reflects the current property value.
- Me.DataGridView.Refresh()
- End If
- End If
- End If
- End Set
- End Property
- <Category("Passwort Verschlüsselung")>
- Public Property EncryptPassword() As Boolean
- Get
- Return Me._encryptPassword
- End Get
- Set(value As Boolean)
- If Me._encryptPassword <> value Then
- Me._encryptPassword = value
- Dim cell As DataGridViewEncryptPasswordTextBoxCell = TryCast(Me.CellTemplate, DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- 'Update the template cell.
- cell.encryptPassword = value
- End If
- If Me.DataGridView IsNot Nothing Then
- 'Update each existing cell in the column.
- For Each row As DataGridViewRow In Me.DataGridView.Rows
- cell = TryCast(row.Cells(Me.Index), DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- cell.encryptPassword = value
- End If
- Next
- 'Force a repaint so the grid reflects the current property value.
- Me.DataGridView.Refresh()
- End If
- End If
- End Set
- End Property
- <Category("Passwort")>
- Public Property UseSystemPasswordChar() As Boolean
- Get
- Return Me._useSystemPasswordChar
- End Get
- Set(ByVal value As Boolean)
- If Me._useSystemPasswordChar <> value Then
- Me._useSystemPasswordChar = value
- Dim cell As DataGridViewEncryptPasswordTextBoxCell = TryCast(Me.CellTemplate, DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- 'Update the template cell.
- cell.UseSystemPasswordChar = value
- End If
- If Me.DataGridView IsNot Nothing Then
- 'Update each existing cell in the column.
- For Each row As DataGridViewRow In Me.DataGridView.Rows
- cell = TryCast(row.Cells(Me.Index), DataGridViewEncryptPasswordTextBoxCell)
- If cell IsNot Nothing Then
- cell.UseSystemPasswordChar = value
- End If
- Next
- 'Force a repaint so the grid reflects the current property value.
- Me.DataGridView.Refresh()
- End If
- End If
- End Set
- End Property
- Public Sub New()
- MyBase.New(New DataGridViewEncryptPasswordTextBoxCell)
- End Sub
- Public Overrides Function Clone() As Object
- If MyBase.Clone() IsNot Nothing Then
- Dim copy As DataGridViewEncryptPasswordTextBoxColumn = DirectCast(MyBase.Clone(), DataGridViewEncryptPasswordTextBoxColumn)
- copy.PasswordChar = Me._passwordChar
- copy.UseSystemPasswordChar = Me._useSystemPasswordChar
- copy.EncryptPassword = Me._encryptPassword
- Return copy
- Else
- Dim myCp As New DataGridViewEncryptPasswordTextBoxColumn
- Return myCp
- End If
- End Function
- End Class
Im Code wird zusätzlich auf eine Klasse TripleDES zugegriffen:
VB.NET-Quellcode
- Option Explicit On
- Option Strict On
- Imports System.IO
- Imports System.Text
- Imports System.Security.Cryptography
- Public Class TripleDES : Implements IFormatProvider, ICustomFormatter
- Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
- Private iv() As Byte = Array.ConvertAll(My.Resources.initVector.Split(CType(",", Char)), Function(str) Byte.Parse(CType(str, String))) '{65, 110, 68, 26, 69, 178, 200, 219}
- Public Function Format(fmt As String, arg As Object, formatProvider As IFormatProvider) As String Implements ICustomFormatter.Format
- If TypeOf arg Is String Then
- Return TripleDES.DecryptText(CType(arg, String))
- Else
- Return Nothing
- End If
- End Function
- Public Function GetFormat(formatType As Type) As Object Implements IFormatProvider.GetFormat
- If formatType Is GetType(ICustomFormatter) Then
- Return Me
- Else
- Return Nothing
- End If
- End Function
- ''' <summary>
- ''' Chiffre-Key
- ''' </summary>
- ''' <returns></returns>
- Public Property ChiffKey As Byte()
- Get
- Return key
- End Get
- Set(value As Byte())
- If Not (value.Count = 24 And value.Min = 1 And value.Max = 24) Then
- Throw New ArgumentException("Das Byte-Array darf ausschließlich eine Größe von 24 Einträge (Min=1, Max=24) umfassen!", "value", Nothing)
- End If
- key = value
- End Set
- End Property
- ''' <summary>
- ''' Initialisierungs-Vector (8 Byte-Array)
- ''' Mehr Angaben werden nicht berücksichtigt
- ''' </summary>
- ''' <returns></returns>
- Public Property InitVector As Byte()
- Get
- Return iv
- End Get
- Set(value As Byte())
- If Not (value.Count = 8 And value.Min = 1 And value.Max = 8) Then
- Throw New ArgumentException("Das Byte-Array darf ausschließlich eine Größe von 8 Einträgen (Min=1, Max=8) umfassen", "value", Nothing)
- Else
- iv = value
- End If
- End Set
- End Property
- ''' <summary>
- ''' Prüft eine Eingabe, ob diese in ein 8-Byte Array konvertiert werden kann
- ''' </summary>
- ''' <param name="value">zu prüfender Inhalt</param>
- ''' <param name="IsValid">Gibt True oder False zurück</param>
- ''' <returns>Byte-Array</returns>
- ''' <remarks>
- ''' Es werden nur 8-Byte oder leere Angaben erlaubt
- ''' </remarks>
- Public Function ConvertToBytes(ByVal value As String, ByVal validCountItems As Integer, ByRef IsValid As Boolean) As Byte()
- If value.IndexOf(",") > 0 Then
- Dim myItems = value.Split(CType(",", Char))
- If myItems.Count = validCountItems Then
- IsValid = True
- For iPos = 0 To myItems.Count - 1
- Dim myItem = myItems(iPos)
- Dim byteValue As Byte
- If Not Byte.TryParse(myItem, byteValue) Then
- IsValid = False
- Exit For
- End If
- Next
- If IsValid Then
- Return Array.ConvertAll(myItems, Function(str) Byte.Parse(CType(str, String)))
- End If
- Else
- IsValid = False
- End If
- Else
- ' Leere Eingabe ist aktzeptabel
- If value = "" Then
- IsValid = True
- End If
- End If
- Return Nothing
- End Function
- ''' <summary>
- ''' Verschüsselung von Inhalten
- ''' </summary>
- ''' <param name="plainText">Zu verschlüsselnder Text</param>
- ''' <returns></returns>
- Public Function Encrypt(ByVal plainText As String, Optional myIV As Byte() = Nothing) As Byte()
- Try
- ' Declare a UTF8Encoding object so we may use the GetByte
- ' method to transform the plainText into a Byte array.
- Dim utf8encoder As UTF8Encoding = New UTF8Encoding()
- Dim inputInBytes() As Byte = utf8encoder.GetBytes(plainText)
- ' Create a new TripleDES service provider
- Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()
- ' The ICryptTransform interface uses the TripleDES
- ' crypt provider along with encryption key and init vector
- ' information
- Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateEncryptor(Me.key, CType(IIf(myIV Is Nothing, Me.iv, myIV), Byte()))
- ' All cryptographic functions need a stream to output the
- ' encrypted information. Here we declare a memory stream
- ' for this purpose.
- Dim encryptedStream As MemoryStream = New MemoryStream()
- Dim cryptStream As CryptoStream = New CryptoStream(encryptedStream,
- cryptoTransform, CryptoStreamMode.Write)
- ' Write the encrypted information to the stream. Flush the information
- ' when done to ensure everything is out of the buffer.
- cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
- cryptStream.FlushFinalBlock()
- encryptedStream.Position = 0
- ' Read the stream back into a Byte array and return it to the calling
- ' method.
- Dim result(CInt(encryptedStream.Length - 1)) As Byte
- encryptedStream.Read(result, 0, CInt(encryptedStream.Length))
- cryptStream.Close()
- Return result
- Catch ex As Exception
- Return Nothing
- End Try
- End Function
- ''' <summary>
- ''' Zu entschlüsselnder Text
- ''' </summary>
- ''' <param name="inputInBytes">Verschlüsselter Inhalt als Byte-Array</param>
- ''' <returns></returns>
- Public Function Decrypt(ByVal inputInBytes() As Byte, Optional myIV As Byte() = Nothing) As String
- Try
- If inputInBytes IsNot Nothing Then
- ' UTFEncoding is used to transform the decrypted Byte Array
- ' information back into a string.
- Dim utf8encoder As UTF8Encoding = New UTF8Encoding()
- Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()
- ' As before we must provide the encryption/decryption key along with
- ' the init vector.
- Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateDecryptor(Me.key, CType(IIf(myIV Is Nothing, Me.iv, myIV), Byte()))
- ' Provide a memory stream to decrypt information into
- Dim decryptedStream As MemoryStream = New MemoryStream()
- Dim cryptStream As CryptoStream = New CryptoStream(decryptedStream, cryptoTransform, CryptoStreamMode.Write)
- cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
- cryptStream.FlushFinalBlock()
- decryptedStream.Position = 0
- ' Read the memory stream and convert it back into a string
- Dim result(CInt(decryptedStream.Length - 1)) As Byte
- decryptedStream.Read(result, 0, CInt(decryptedStream.Length))
- cryptStream.Close()
- Dim myutf As UTF8Encoding = New UTF8Encoding()
- Return myutf.GetString(result)
- Else
- Return Nothing
- End If
- Catch ex As Exception
- Return Nothing
- End Try
- End Function
- ''' <summary>
- ''' Entschlüsselung von Textinhalten
- ''' </summary>
- ''' <param name="value">Verschlüsselter Inhalt</param>
- ''' <param name="initVector">Initialisierungsvektor</param>
- ''' <returns>
- ''' Entschlüsselter Text
- ''' Falls der verschlüsselte Inhalt nicht entschlüsselt werden kann, wird der Wert von value unverändert zurückgegeben</returns>
- ''' <remarks>
- ''' Über den Initialisierungsvector wird die Verschlüsselung festgelegt
- ''' Dieser muss beim Verschlüsseln und Entschlüsseln identisch sein.
- ''' </remarks>
- Friend Function DecryptText(ByRef value As String, initVector As Byte()) As String
- Dim myDES As New TripleDES
- value = CType(IIf(value Is Nothing, "", value), String)
- If value.Length > 0 Then
- Dim pwDecryptByte As Byte() = Nothing
- Try
- ' Testen, ob Inhalt vollständig in Byte konvertiert werden kann...
- Dim bReadyToConvert As Boolean = True
- For Each valByte In value.Split(CType(",", Char()))
- Dim result As Byte
- If Not Byte.TryParse(valByte, result) Then
- bReadyToConvert = False
- Exit For
- End If
- Next
- If bReadyToConvert Then
- pwDecryptByte = Array.ConvertAll(value.Split(CType(",", Char())), Function(Str) Byte.Parse(Str))
- Else
- pwDecryptByte = Nothing
- End If
- Catch ex As Exception
- Return value
- End Try
- Try
- Dim TextDecrypt = myDES.Decrypt(pwDecryptByte, initVector)
- Return CType(IIf(TextDecrypt Is Nothing, value, TextDecrypt), String)
- Catch ex As Exception
- Return value
- End Try
- Else
- Return ""
- End If
- End Function
- ''' <summary>
- ''' Entschlüsselung von Textinhalten
- ''' </summary>
- ''' <param name="value">Verschlüsselter Inhalt</param>
- ''' <returns>
- ''' Entschlüsselter Text
- ''' Falls der verschlüsselte Inhalt nicht entschlüsselt werden kann, wird der Wert von value unverändert zurückgegeben</returns>
- Friend Shared Function DecryptText(ByRef value As String) As String
- Dim myDES As New TripleDES
- Return myDES.DecryptText(value, Nothing)
- End Function
- ''' <summary>
- ''' Verschlüsselung von Inhalten
- ''' </summary>
- ''' <param name="value">zu verschlüsselnder Textinhalt </param>
- ''' <param name="initVector">Initialisierungsvektor</param>
- ''' <returns></returns>
- ''' <remarks>
- ''' Über den Initialisierungsvector wird die Verschlüsselung festgelegt
- ''' Dieser muss beim Verschlüsseln und Entschlüsseln identisch sein.
- ''' </remarks>
- Friend Function EncryptText(ByRef value As String, initVector As Byte()) As String
- Dim myDES As New TripleDES
- If value.Length > 0 Then
- Try
- Dim pwBytes As Byte() = myDES.Encrypt(value, initVector)
- Return String.Join(",", pwBytes)
- Catch ex As Exception
- Return ""
- End Try
- Else
- Return ""
- End If
- End Function
- ''' <summary>
- ''' Verschlüsselung von Inhalten
- ''' </summary>
- ''' <param name="value">zu verschlüsselnder Textinhalt </param>
- ''' <returns></returns>
- Friend Shared Function EncryptText(ByRef value As String) As String
- Dim myDES As New TripleDES
- If value.Length > 0 Then
- Try
- Dim pwBytes As Byte() = myDES.Encrypt(value)
- Return String.Join(",", pwBytes)
- Catch ex As Exception
- Return ""
- End Try
- Else
- Return ""
- End If
- End Function
- End Class
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „BigBen2003“ ()