Feedback

VB - Den SHA1 Hash einer Datei ermitteln

Veröffentlicht von am 6/3/2006
(2 Bewertungen)
Den SHA1 Hash einer Datei ermitteln
Imports System.Security.Cryptography
Imports System.Text
Imports System.IO

Public Function SHA1FileHash(ByVal sFile As String) As String
    Dim SHA1 As New SHA1CryptoServiceProvider
    Dim Hash As Byte()
    Dim Result As String = ""
    Dim Tmp As String = ""

    Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
    SHA1.ComputeHash(FN)
    FN.Close()

    Hash = SHA1.Hash
    For i As Integer = 0 To Hash.Length - 1
        Tmp = Hex(Hash(i))
        If Len(Tmp) = 1 Then Tmp = "0" & Tmp
        Result += Tmp
    Next
    Return Result
End Function
Abgelegt unter Hash, Datei, SHA1, Cryptography.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!