md5 Codeaus *.dll Datei auslesen und konvertiern

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von ChaosBernd.

    md5 Codeaus *.dll Datei auslesen und konvertiern

    Hallo Com,

    ich arbeite gerade an einem Programm,und nun bin ich beim "Registrieren,Anmelden und Passwort vergessen".
    Also beim Registrieren Frage ich ich nach Name,Passwort und Sicherheitswort.Passwort und Sicherheitswort werden mithlife von dem Code hier in einen md5 Code umgewandelt und in einen *.dll Datei gespeichert(Bild siehe Anhang).

    Mein Code zum verschlüsseln:

    VB.NET-Quellcode

    1. Imports System.Security.Cryptography
    2. Imports System.IO
    3. Imports System.Text
    4. Public Class Form3
    5. Inherits System.Windows.Forms.Form
    6. Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
    7. Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
    8. Public Function INI_ReadValueFromFile(ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strFile As String) As String
    9. 'Funktion zum Lesen
    10. 'strSection = Sektion in der INI-Datei
    11. 'strKey = Name des Schlüssels
    12. 'strDefault = Standardwert, wird zurückgegeben, wenn der Wert in der INI-Datei nicht gefunden wurde
    13. 'strFile = Vollständiger Pfad zur INI-Datei
    14. Dim strTemp As String = Space(1024), lLength As Integer
    15. lLength = GetPrivateProfileString(strSection, strKey, strDefault, strTemp, strTemp.Length, strFile)
    16. Return (strTemp.Substring(0, lLength))
    17. End Function
    18. Public Function INI_WriteValueToFile(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String, ByVal strFile As String) As Boolean
    19. 'Funktion zum Schreiben
    20. 'strSection = Sektion in der INI-Datei
    21. 'strKey = Name des Schlüssels
    22. 'strValue = Wert, der geschrieben werden soll
    23. 'strFile = Vollständiger Pfad zur INI-Datei
    24. Return (Not (WritePrivateProfileString(strSection, strKey, strValue, strFile) = 0))
    25. End Function
    26. Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    27. 'Einstellungen speichern
    28. INI_WriteValueToFile(TextBox1.Text, "Name", TextBox1.Text, ".\Einstellungen.dll")
    29. INI_WriteValueToFile(TextBox1.Text, "Passwort", TextBox4.Text, ".\Einstellungen.dll")
    30. INI_WriteValueToFile(TextBox1.Text, "Sicherheitswort", TextBox5.Text, ".\Einstellungen.dll")
    31. INI_WriteValueToFile(TextBox1.Text, "Redakteur", RadioButton1.Checked, ".\Einstellungen.dll")
    32. INI_WriteValueToFile(TextBox1.Text, "Supporter", RadioButton2.Checked, ".\Einstellungen.dll")
    33. End Sub


    Und mein Code zum auslesen der NICHT Funktioniert:

    VB.NET-Quellcode

    1. Imports System.Security.Cryptography
    2. Imports System.IO
    3. Imports System.Text
    4. Public Class Form5
    5. Inherits System.Windows.Forms.Form
    6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7. Dim suchwort As String
    8. suchwort = TextBox1.Text
    9. For Each Zeile As String In System.IO.File.ReadAllLines(".\Einstellungen.dll")
    10. If Zeile.Contains(suchwort) Then
    11. Dim rd As New RijndaelManaged
    12. Dim rijndaelIvLength As Integer = 16
    13. Dim md5 As New MD5CryptoServiceProvider
    14. Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(TextBox2.Text))
    15. md5.Clear()
    16. Dim encdata() As Byte = Convert.FromBase64String(TextBox2.Text)
    17. Dim ms As New MemoryStream(encdata)
    18. Dim iv(15) As Byte
    19. ms.Read(iv, 0, rijndaelIvLength)
    20. rd.IV = iv
    21. rd.Key = key
    22. Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read)
    23. Dim data(ms.Length - rijndaelIvLength) As Byte
    24. Dim i As Integer = cs.Read(data, 0, data.Length)
    25. MsgBox(System.Text.Encoding.UTF8.GetString(data, 0, i))
    26. cs.Close()
    27. rd.Clear()
    28. Exit For
    29. End If
    30. Next
    31. End Sub
    32. End Class


    Was mach ich Falsch.
    Ich hab 3seit 3 Stunden in Google und hier gesucht,hab alles mögliche probiert.Ich komm aber nicht weiter. :( ;( :S :cursing:

    grüße peti03100
    Bilder
    • EinstellungenDLL.jpg

      16,66 kB, 503×442, 181 mal angesehen
    Da gibts ne menge, beispiele:
    SHA - XXX (XXX ist glaube ich mal das charset)
    Base64
    Base128
    Rot13
    etc.
    Das sind die , die mir so spontan einfallen.
    Aber zu dem würde ich bei Base64 zwei oder 3 chars mittendrin rein nehmen.

    Aber wenn du bei dem aller sicherstem MD5 bleiben willst:
    Speichere mit z.b. md5(string)
    und prüfe mit md5(string)

    :), so läufts bei vielen websites auch so!! :)
    Viel glück!
    oder hier bei Dr. Peter Fleischer steht auch eine schöne Lösung

    edit:
    sorry falscher Link. habe ihn nicht mehr.
    aber hier der Codeausschnitt
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dateien Laden Verschlüsseln und dann Speichern
    2. Option Explicit On
    3. Option Infer On
    4. Option Strict On
    5. Imports System.Xml.Serialization
    6. Imports System.IO
    7. Imports System.Security.Cryptography
    8. Module Module1
    9. Sub Main()
    10. Try
    11. '
    12. ' Teil 1 Datei verschlüsseln und ablegen
    13. '
    14. Using fs As New FileStream("c:\temp\x1.x", FileMode.Open)
    15. ' verschlüsseln
    16. SaveEncrypted("c:\temp\x2.x", fs)
    17. End Using
    18. '
    19. ' Teil 2 Datei wieder entschlüsseln
    20. '
    21. Using fs As New FileStream("c:\temp\x3.x", FileMode.Create)
    22. ' entschlüsseln
    23. LoadEncrypted("c:\temp\x2.x", fs)
    24. End Using
    25. '
    26. Console.WriteLine("Vorgang abgeschlossen")
    27. Catch ex As Exception
    28. Console.WriteLine(ex.Message)
    29. End Try
    30. '
    31. Console.ReadLine()
    32. End Sub
    33. ''' <summary>
    34. ''' Schlüssel für Ver- und Entschlüsselung
    35. ''' </summary>
    36. ''' <remarks></remarks>
    37. Dim desKey() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
    38. Dim desIV() As Byte = {1, 2, 3, 4, 5, 6, 7, 9}
    39. ''' <summary>
    40. ''' XML-Datenstrom verschlüsseln und in Datei ablegen
    41. ''' </summary>
    42. ''' <param name="filename">Dateiname für Ablage</param>
    43. ''' <param name="str">IO-Stream (z.B. MemoryStream) mit Daten</param>
    44. ''' <remarks></remarks>
    45. Private Sub SaveEncrypted(ByVal filename As String, ByVal str As Stream)
    46. Dim fout As FileStream = Nothing
    47. Dim encStream As CryptoStream = Nothing
    48. Try
    49. 'Create the file streams to handle the output files.
    50. fout = New FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)
    51. fout.SetLength(0)
    52. 'Create variables to help with read and write.
    53. Dim bin(99) As Byte 'This is intermediate storage for the encryption.
    54. Dim rdlen As Long = 0 'This is the total number of bytes written.
    55. Dim totlen As Long = str.Length 'Total length of the input file.
    56. Dim lng As Integer ' This is the number of bytes to be written at a time.
    57. 'Creates the default implementation, which is RijndaelManaged.
    58. Dim des As New DESCryptoServiceProvider
    59. encStream = New CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write)
    60. 'Read from the input file, then encrypt and write to the output file.
    61. str.Position = 0
    62. While rdlen < totlen
    63. lng = str.Read(bin, 0, bin.GetUpperBound(0))
    64. encStream.Write(bin, 0, lng)
    65. rdlen = Convert.ToInt32(rdlen + lng)
    66. End While
    67. Catch ex As Exception
    68. MsgBox(ex.Message)
    69. Finally
    70. If encStream IsNot Nothing Then encStream.Dispose()
    71. If fout IsNot Nothing Then fout.Close()
    72. End Try
    73. End Sub
    74. ''' <summary>
    75. ''' XML-Datenstrom aus Datei laden und entschlüsseln
    76. ''' </summary>
    77. ''' <param name="filename">Dateiname zum Einlesen</param>
    78. ''' <param name="str">IO-Stream (z.B. MemoryStream) mit Daten</param>
    79. ''' <remarks></remarks>
    80. Private Sub LoadEncrypted(ByVal filename As String, ByVal str As Stream)
    81. Dim fin As System.IO.FileStream = Nothing
    82. Dim decStream As CryptoStream = Nothing
    83. Try
    84. fin = New FileStream(filename, FileMode.Open, FileAccess.Read)
    85. 'Create variables to help with read and write.
    86. Dim bin(10000) As Byte ' This is intermediate storage for the encryption.
    87. Dim rdlen As Long = 0 'This is the total number of bytes written.
    88. Dim totlen As Long = fin.Length 'Total length of the input file.
    89. Dim lng As Integer ' This is the number of bytes to be written at a time.
    90. 'Creates the default implementation, which is RijndaelManaged.
    91. Dim des As New DESCryptoServiceProvider
    92. decStream = New CryptoStream(fin, des.CreateDecryptor(desKey, desIV), CryptoStreamMode.Read)
    93. 'Read from the input file, then encrypt and write to the output file.
    94. lng = decStream.Read(bin, 0, bin.GetUpperBound(0) + 1)
    95. While lng > 0
    96. str.Write(bin, 0, lng)
    97. rdlen = Convert.ToInt32(rdlen + lng)
    98. lng = decStream.Read(bin, 0, bin.GetUpperBound(0) + 1)
    99. End While
    100. Catch ex As Exception
    101. MsgBox(ex.Message)
    102. Finally
    103. If decStream IsNot Nothing Then decStream.Dispose()
    104. If fin IsNot Nothing Then fin.Dispose()
    105. End Try
    106. End Sub
    107. End Module

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „ChaosBernd“ ()