API Hash für Authentifizierung

  • VB.NET
  • .NET (FX) 4.0

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von Lukas22.

    API Hash für Authentifizierung

    Hallo Zusammen,
    wie kann ich das in Visual basic schreiben.

    function generateHash()
    {

    $initKey = 'EXsl4ywgDR5mR3sTGwws9Ikl2ocSKZlvhxoFTv8Au3MaV5UqrEIJORVF5PmFNy';
    $appName = 'NameDerApp';
    $date = gmdate('dmY');
    $hash = "";

    for($i = 0; $i <= 200; $i++)
    $hash = sha1($hash . $initKey . $appName . $date);

    return $hash;
    }

    Original Link:
    xentral.com/helpdesk/api
    Geht es dir darum, wie man einen SHA1 Hash berechnet?

    VB.NET-Quellcode

    1. Public Function SHA1_Hash(InputString As String) As String
    2. Using SHA1 As New System.Security.Cryptography.SHA1Managed
    3. Dim UTF8 As New System.Text.UTF8Encoding
    4. Return SHA1.ComputeHash(UTF8.GetBytes(InputString)).ToString
    5. End Using
    6. End Function
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Hey..
    Ich habe mal ein Projekt gemacht und auch getestet.. funktioniert soweit.
    Musst du dann eben abändern jenachdem wie du es benötigst.

    VB.NET-Quellcode

    1. Imports System.Security.Cryptography
    2. Imports System.Text
    3. Module Module1
    4. Sub Main()
    5. Console.WriteLine(GenerateHash())
    6. Console.ReadKey()
    7. End Sub
    8. Private Function GenerateHash() As String
    9. Dim initKey As String = "EXsl4ywgDR5mR3sTGwws9Ikl2ocSKZlvhxoFTv8Au3MaV5UqrEIJORVF5PmFNy"
    10. Dim appName As String = "NameDerApp"
    11. Dim dateT As DateTime = New DateTime()
    12. Dim hash As String = ""
    13. For i As Integer = 0 To 200
    14. Next
    15. hash = Sha1(hash & initKey & appName & dateT.ToString("dmY"))
    16. Return hash
    17. End Function
    18. Private Function Sha1(ByVal input As String) As String
    19. Using sha1hash As SHA1Managed = New SHA1Managed()
    20. Dim hash = sha1hash.ComputeHash(Encoding.UTF8.GetBytes(input))
    21. Dim sb = New StringBuilder(hash.Length * 2)
    22. For Each b As Byte In hash
    23. 'Wenn du Lowercase möchtest ändere das "X2" um in "x2"
    24. sb.Append(b.ToString("X2"))
    25. Next
    26. Return sb.ToString()
    27. End Using
    28. End Function
    29. End Module
    Hallo,
    danke für die Antwort. Wie kann ich das noch umsetzen.

    function SendRequest($methodname,$xml,$hash) {
    $url = 'http://server.com/index.php?module=api&action='.$methodname.'&hash='.$hash; $data = array('xml' => $xml, 'md5sum' => md5($xml));

    Vielen Dank im Voraus.