Hallo,
ich arbeite schon länger an einem kleinem Projekt und benötige nun etwas hilfe. Ich versuche meine ListView-Einträge verschlüsselt zu speichern, was ich auch geschafft habe:
Nun will ich das ganze wieder entschlüsseln und die Einträge in die Listview zu laden.
Das ganze habe ich versucht mit diesem Tutorial .
ich arbeite schon länger an einem kleinem Projekt und benötige nun etwas hilfe. Ich versuche meine ListView-Einträge verschlüsselt zu speichern, was ich auch geschafft habe:
VB.NET-Quellcode
- Public Function ListViewSave(ByRef LstVw As ListView, ByVal Path As String)
- Dim ListViewContent As String = ""
- For I As Integer = 0 To LstVw.Items.Count - 1
- ListViewContent += LstVw.Items.Item(I).Text & "|"
- For Int As Integer = 0 To LstVw.Items.Item(I).SubItems().Count - 1
- ListViewContent += LstVw.Items.Item(I).SubItems(Int).Text & "|"
- Next
- ListViewContent += vbNewLine
- Next
- If System.IO.File.Exists(Path) Then
- System.IO.File.Delete(Path)
- End If
- 'Verschlüsselung
- Dim rd As New RijndaelManaged
- Dim EncString As String
- Dim md5 As New MD5CryptoServiceProvider
- Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("bb43da1314aae739ba84b19b5a8525ba"))
- md5.Clear()
- rd.Key = key
- rd.GenerateIV()
- Dim iv() As Byte = rd.IV
- Dim ms As New MemoryStream
- ms.Write(iv, 0, iv.Length)
- Dim cs As New CryptoStream(ms, rd.CreateEncryptor, CryptoStreamMode.Write)
- Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes(ListViewContent)
- cs.Write(data, 0, data.Length)
- cs.FlushFinalBlock()
- Dim encdata() As Byte = ms.ToArray()
- EncString = Convert.ToBase64String(encdata)
- cs.Close()
- rd.Clear()
- System.IO.File.AppendAllText(Path, EncString)
- End Function
Nun will ich das ganze wieder entschlüsseln und die Einträge in die Listview zu laden.
VB.NET-Quellcode
- Public Function ListViewLoad(ByRef LstVw As ListView, ByVal Path As String)
- Dim sLine As String
- Dim sItem() As String
- Dim ItemX As ListViewItem
- Dim IntCols As Integer
- IntCols = LstVw.Columns.Count
- FileOpen(1, Path, OpenMode.Input)
- With LstVw.Items
- While Not EOF(1)
- sLine = LineInput(1)
- sItem = Split(sLine, "|")
- ItemX = .Add(sItem(0), sItem(1))
- For I = 2 To IntCols
- ItemX.SubItems.Add(sItem(I))
- Next I
- End While
- End With
- FileClose(1)
- End Function
Das ganze habe ich versucht mit diesem Tutorial .