ListView verschlüsselt speichern bzw. laden

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    ListView verschlüsselt speichern bzw. laden

    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:

    VB.NET-Quellcode

    1. Public Function ListViewSave(ByRef LstVw As ListView, ByVal Path As String)
    2. Dim ListViewContent As String = ""
    3. For I As Integer = 0 To LstVw.Items.Count - 1
    4. ListViewContent += LstVw.Items.Item(I).Text & "|"
    5. For Int As Integer = 0 To LstVw.Items.Item(I).SubItems().Count - 1
    6. ListViewContent += LstVw.Items.Item(I).SubItems(Int).Text & "|"
    7. Next
    8. ListViewContent += vbNewLine
    9. Next
    10. If System.IO.File.Exists(Path) Then
    11. System.IO.File.Delete(Path)
    12. End If
    13. 'Verschlüsselung
    14. Dim rd As New RijndaelManaged
    15. Dim EncString As String
    16. Dim md5 As New MD5CryptoServiceProvider
    17. Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes("bb43da1314aae739ba84b19b5a8525ba"))
    18. md5.Clear()
    19. rd.Key = key
    20. rd.GenerateIV()
    21. Dim iv() As Byte = rd.IV
    22. Dim ms As New MemoryStream
    23. ms.Write(iv, 0, iv.Length)
    24. Dim cs As New CryptoStream(ms, rd.CreateEncryptor, CryptoStreamMode.Write)
    25. Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes(ListViewContent)
    26. cs.Write(data, 0, data.Length)
    27. cs.FlushFinalBlock()
    28. Dim encdata() As Byte = ms.ToArray()
    29. EncString = Convert.ToBase64String(encdata)
    30. cs.Close()
    31. rd.Clear()
    32. System.IO.File.AppendAllText(Path, EncString)
    33. End Function


    Nun will ich das ganze wieder entschlüsseln und die Einträge in die Listview zu laden.

    VB.NET-Quellcode

    1. Public Function ListViewLoad(ByRef LstVw As ListView, ByVal Path As String)
    2. Dim sLine As String
    3. Dim sItem() As String
    4. Dim ItemX As ListViewItem
    5. Dim IntCols As Integer
    6. IntCols = LstVw.Columns.Count
    7. FileOpen(1, Path, OpenMode.Input)
    8. With LstVw.Items
    9. While Not EOF(1)
    10. sLine = LineInput(1)
    11. sItem = Split(sLine, "|")
    12. ItemX = .Add(sItem(0), sItem(1))
    13. For I = 2 To IntCols
    14. ItemX.SubItems.Add(sItem(I))
    15. Next I
    16. End While
    17. End With
    18. FileClose(1)
    19. End Function


    Das ganze habe ich versucht mit diesem Tutorial .