Get File MD5 Hash Using VB6

To get a file’s MD5 Hash using Visual Basic 6, download and add the following clsMD5 class to your VB project.

Download: clsMD5.zip

 

Add a command button (Command1), a text box (Text1) and use the following code:

Private Function GetFileMD5(ByVal FileName As String) As String
    Dim MD5 As New clsMD5, FF As Integer, Buff() As Byte
    Const BuffSize As Long = 2 ^ 16 ' (64 KBytes)

'    On Error GoTo ErrExit
    FF = FreeFile
    Open FileName For Binary Access Read As FF
        MD5.MD5Init
 
        Do Until Loc(FF) >= LOF(FF)
            If Loc(FF) + BuffSize > LOF(FF) Then
                ReDim Buff(LOF(FF) - Loc(FF) - 1)
            Else
                ReDim Buff(BuffSize - 1)
            End If
 
            Get FF, , Buff
            MD5.MD5Update UBound(Buff) + 1, Buff
        Loop
 
        MD5.MD5Final
        GetFileMD5 = MD5.GetValues
    Close FF
 
    Exit Function
ErrExit:
    Err.Clear
    GetFileMD5 = ""
End Function
 
Private Sub Command1_Click()
Text1.Text = GetFileMD5("c:\example.exe")
End Sub

Related posts:

Extract Links or URLs from A Web Page - Visual Basic 6 (VB6)

Tags : , , , ,

If you enjoyed this post, please leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

2 Comments

Leave Comment