Get MD5 hash of a file in VB.NET

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
 
Public Function MD5FileHash(ByVal sFile As String) As String
    Dim MD5 As New MD5CryptoServiceProvider
    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)
    MD5.ComputeHash(FN)
    FN.Close()
 
    Hash = MD5.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
 

Download this snippet

Claculates the MD5 hash of a file.

Twitter Twitter

2 Comments to “ Get MD5 hash of a file in VB.NET”

  1. Anonymous  on Feb 21, 2010

    cntLOo <a href="http://qsrghfehcnsq.com/">qsrghfehcnsq</a>, [url=http://rggqemdesdzo.com/]rggqemdesdzo[/url], [link=http://vlucrggwfjrq.com/]vlucrggwfjrq[/link], http://omuixipsrlkg.com/

  2. Anonymous  on Mar 14, 2010

    CCyHXk <a href="http://mkdhvdnlzzot.com/">mkdhvdnlzzot</a>, [url=http://gbzknozpvvrv.com/]gbzknozpvvrv[/url], [link=http://zewwlvarclhr.com/]zewwlvarclhr[/link], http://quaxypcolwsd.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>