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?
Printable View
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?
Should I give you the full code ? :D or should I give you the MD5 class, and you'll take it from there ?
Anyway is fine with me :)
Here:
VB Code:
Option Explicit 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 Form_Load() Debug.Print GetFileMD5("C:\Test_001.wav") End Sub
Hehe :blush:
I just noticed, the class does it for you :D (DigestFileToHexStr...)VB Code:
Private Sub Form_Load() Dim MD5 As New clsMD5 Debug.Print MD5.DigestFileToHexStr("C:\Test_001.wav") End Sub
[edit]
Well, at least with my code you can add a progress bar to it :)
works great! Thanks :)