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:
Und mein Code zum auslesen der NICHT Funktioniert:
Was mach ich Falsch.
Ich hab 3seit 3 Stunden in Google und hier gesucht,hab alles mögliche probiert.Ich komm aber nicht weiter.
grüße peti03100
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
- Imports System.Security.Cryptography
- Imports System.IO
- Imports System.Text
- Public Class Form3
- Inherits System.Windows.Forms.Form
- 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
- 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
- Public Function INI_ReadValueFromFile(ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strFile As String) As String
- 'Funktion zum Lesen
- 'strSection = Sektion in der INI-Datei
- 'strKey = Name des Schlüssels
- 'strDefault = Standardwert, wird zurückgegeben, wenn der Wert in der INI-Datei nicht gefunden wurde
- 'strFile = Vollständiger Pfad zur INI-Datei
- Dim strTemp As String = Space(1024), lLength As Integer
- lLength = GetPrivateProfileString(strSection, strKey, strDefault, strTemp, strTemp.Length, strFile)
- Return (strTemp.Substring(0, lLength))
- End Function
- Public Function INI_WriteValueToFile(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String, ByVal strFile As String) As Boolean
- 'Funktion zum Schreiben
- 'strSection = Sektion in der INI-Datei
- 'strKey = Name des Schlüssels
- 'strValue = Wert, der geschrieben werden soll
- 'strFile = Vollständiger Pfad zur INI-Datei
- Return (Not (WritePrivateProfileString(strSection, strKey, strValue, strFile) = 0))
- End Function
- Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
- 'Einstellungen speichern
- INI_WriteValueToFile(TextBox1.Text, "Name", TextBox1.Text, ".\Einstellungen.dll")
- INI_WriteValueToFile(TextBox1.Text, "Passwort", TextBox4.Text, ".\Einstellungen.dll")
- INI_WriteValueToFile(TextBox1.Text, "Sicherheitswort", TextBox5.Text, ".\Einstellungen.dll")
- INI_WriteValueToFile(TextBox1.Text, "Redakteur", RadioButton1.Checked, ".\Einstellungen.dll")
- INI_WriteValueToFile(TextBox1.Text, "Supporter", RadioButton2.Checked, ".\Einstellungen.dll")
- End Sub
Und mein Code zum auslesen der NICHT Funktioniert:
VB.NET-Quellcode
- Imports System.Security.Cryptography
- Imports System.IO
- Imports System.Text
- Public Class Form5
- Inherits System.Windows.Forms.Form
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim suchwort As String
- suchwort = TextBox1.Text
- For Each Zeile As String In System.IO.File.ReadAllLines(".\Einstellungen.dll")
- If Zeile.Contains(suchwort) Then
- Dim rd As New RijndaelManaged
- Dim rijndaelIvLength As Integer = 16
- Dim md5 As New MD5CryptoServiceProvider
- Dim key() As Byte = md5.ComputeHash(Encoding.UTF8.GetBytes(TextBox2.Text))
- md5.Clear()
- Dim encdata() As Byte = Convert.FromBase64String(TextBox2.Text)
- Dim ms As New MemoryStream(encdata)
- Dim iv(15) As Byte
- ms.Read(iv, 0, rijndaelIvLength)
- rd.IV = iv
- rd.Key = key
- Dim cs As New CryptoStream(ms, rd.CreateDecryptor, CryptoStreamMode.Read)
- Dim data(ms.Length - rijndaelIvLength) As Byte
- Dim i As Integer = cs.Read(data, 0, data.Length)
- MsgBox(System.Text.Encoding.UTF8.GetString(data, 0, i))
- cs.Close()
- rd.Clear()
- Exit For
- End If
- Next
- End Sub
- 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.
grüße peti03100