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.



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

        Do Until Loc(FF) >= LOF(FF)
            If Loc(FF) + BuffSize > LOF(FF) Then
                ReDim Buff(LOF(FF) - Loc(FF) - 1)
                ReDim Buff(BuffSize - 1)
            End If

            Get FF, , Buff
            MD5.MD5Update UBound(Buff) + 1, Buff

        GetFileMD5 = MD5.GetValues
    Close FF

    Exit Function
    GetFileMD5 = ""
End Function

Private Sub Command1_Click()
Text1.Text = GetFileMD5("c:\example.exe")
End Sub

2 thoughts on “Get File MD5 Hash Using VB6”

Leave a Reply

Your email address will not be published. Required fields are marked *