Results 1 to 6 of 6

Thread: Calculate MD5 hash of a file [resolved]

  1. #1

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Resolved Calculate MD5 hash of a file [resolved]

    I need to calculate MD5 hash value of a file. I've been searching around but with no luck.

    Anyone have any pointers or ideas?
    Last edited by baja_yu; Jun 20th, 2005 at 01:00 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Calculate MD5 hash of a file

    Should I give you the full code ? or should I give you the MD5 class, and you'll take it from there ?

  3. #3

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Calculate MD5 hash of a file

    Anyway is fine with me

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Calculate MD5 hash of a file

    Here:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Function GetFileMD5(ByVal FileName As String) As String
    4.     Dim MD5 As New clsMD5, FF As Integer, Buff() As Byte
    5.     Const BuffSize As Long = 2 ^ 16 ' (64 KBytes)
    6.    
    7.     On Error GoTo ErrExit
    8.     FF = FreeFile
    9.     Open FileName For Binary Access Read As FF
    10.         MD5.MD5Init
    11.        
    12.         Do Until Loc(FF) >= LOF(FF)
    13.             If Loc(FF) + BuffSize > LOF(FF) Then
    14.                 ReDim Buff(LOF(FF) - Loc(FF) - 1)
    15.             Else
    16.                 ReDim Buff(BuffSize - 1)
    17.             End If
    18.            
    19.             Get FF, , Buff
    20.             MD5.MD5Update UBound(Buff) + 1, Buff
    21.         Loop
    22.        
    23.         MD5.MD5Final
    24.         GetFileMD5 = MD5.GetValues
    25.     Close FF
    26.    
    27.     Exit Function
    28. ErrExit:
    29.     Err.Clear
    30.     GetFileMD5 = ""
    31. End Function
    32.  
    33. Private Sub Form_Load()
    34.     Debug.Print GetFileMD5("C:\Test_001.wav")
    35. End Sub
    Attached Files Attached Files

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Calculate MD5 hash of a file

    Hehe
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim MD5 As New clsMD5
    3.     Debug.Print MD5.DigestFileToHexStr("C:\Test_001.wav")
    4. End Sub
    I just noticed, the class does it for you (DigestFileToHexStr...)

    [edit]
    Well, at least with my code you can add a progress bar to it

  6. #6

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Calculate MD5 hash of a file

    works great! Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width