MD5-Hash erstellen

  • VB.NET

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

    MD5-Hash erstellen

    Hi, ich möchte von z.B. "VB-Paradise" den MD5-Hash machen.

    Dies versuche ich so:

    VB.NET-Quellcode

    1. Imports System.Security.Cryptography
    2. Imports System.Text
    3. Imports System
    4. Imports System.IO
    5. Imports System.Net
    6. Public Class Form1
    7. Shared string1 As String
    8. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9. Try
    10. Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://datei.auf/server"), HttpWebRequest)
    11. Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
    12. Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
    13. string1 = reader.ReadToEnd()
    14. If Not response Is Nothing Then response.Close()
    15. MsgBox(string1) 'um zu prüfen ob es der richtige hash ist, ja es ist immer der richtige also richtig gelesen
    16. Catch
    17. End Try
    18. End Sub
    19. Private Function GenerateHash(ByVal SourceText As String) As String
    20. Dim Ue As New UnicodeEncoding()
    21. Dim ByteSourceText() As Byte = Ue.GetBytes(SourceText)
    22. Dim Md5 As New MD5CryptoServiceProvider()
    23. Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
    24. Return Convert.ToBase64String(ByteHash)
    25. End Function


    Dann versuche ich, die Funktion per buttonklcik auszuführen:

    VB.NET-Quellcode

    1. MsgBox(GenerateHash(TextBox1.Text))


    leider steht in der msgbox kein hash, sondern
    +Y+YKeZbd8lKhEHD00iK0g==
    warum? und wie krieg ichs wieder weg?

    mfg serials
    | Keine Fragen per PN oder Skype.

    VB.NET-Quellcode

    1. Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes("VB-Paradise")
    2. Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider()
    3. Dim result As Byte() = md5.ComputeHash(data)
    Gruß, Agent Smith 8-)

    activeFlags = (lazy OR weary)

    Lemgo-Verschwörung | Mathematics | VB-Paradise in blau
    schonmal vielen dank, aber es klaptt immer noch nicht.

    der code in der function:

    VB.NET-Quellcode

    1. Private Function GenerateHash(ByVal SourceText As String) As String
    2. Dim data() As Byte = Encoding.UTF8.GetBytes(SourceText)
    3. Dim Md5 As New MD5CryptoServiceProvider()
    4. Dim result As Byte() = Md5.ComputeHash(data)
    5. Return Convert.ToBase64String(data)
    6. End Function


    Ergebnis in der MsgBox:
    YXJuaWtvZnJvbW5lcGFsc2thdGVib2FyZHNjcnlwdA==
    Ich verstehe das nicht ?( ?(
    | Keine Fragen per PN oder Skype.
    klappt auch nicht

    ich benutze jetzt:

    VB.NET-Quellcode

    1. Private Function ComputeMD5(ByVal str As String, _
    2. ByVal encoding As Encoding) As String
    3. Dim input As Byte() = encoding.GetBytes(str)
    4. Dim hash As Byte() = (New MD5CryptoServiceProvider()).ComputeHash(input)
    5. Return encoding.GetString(hash)
    6. End Function


    und zum aufrufen:

    VB.NET-Quellcode

    1. MsgBox(ComputeMD5(TextBox1.Text, Encoding.ASCII))


    jetzt kommen in der msgbox ein paar vierecke(nicht darstellbare zeichen), klammern und sonstiger schund.

    der code mag mich nicht :D
    | Keine Fragen per PN oder Skype.

    VB.NET-Quellcode

    1. Private Function MD5CON(ByVal ConvertedHash As String) As String
    2. Dim Res As String = ""
    3. Try
    4. Dim MD5 As New MD5CryptoServiceProvider
    5. Dim Data As Byte()
    6. Dim Result As Byte()
    7. Dim Tmp As String = ""
    8. Data = Encoding.ASCII.GetBytes(ConvertedHash)
    9. Result = MD5.ComputeHash(Data)
    10. For i As Integer = 0 To Result.Length - 1
    11. Tmp = Hex(Result(i))
    12. If Len(Tmp) = 1 Then Tmp = "0" & Tmp
    13. Res += Tmp
    14. Next
    15. Catch ex As Exception
    16. MsgBox("Hash konne nicht erstellt werden.", MsgBoxStyle.Critical)
    17. Res = ""
    18. End Try
    19. Return Res
    20. End Function


    Ich benutze die Funktion von mir und die funkt einwandfrei :D