Solved

How To Get Md5 of any file : vb6

Posted on 2004-09-28
5
237 Views
Last Modified: 2008-01-09
Hello Experts

How can i alter the code in  ( http://www.frez.co.uk/MD5.zip )

so i can get the md5 signature when i
type a filename in a text1.text  box

output to

text2.text

thanks Experts

 
0
Comment
Question by:Jimmyx1000
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 12176159
I don't have a compiler right now, but couldn't be hard. Please verify.
I have created a new function called MD5File(), it opens a file specified file by name (full path is needed) and calculates MD5.
Hope there are not errors.

Public Function MD5File(Filename As String) As String
    Dim x() As Long
    Dim k   As Long
    Dim AA  As Long
    Dim BB  As Long
    Dim CC  As Long
    Dim DD  As Long
    Dim a   As Long
    Dim b   As Long
    Dim c   As Long
    Dim d   As Long
   
    Const S11 As Long = 7
    Const S12 As Long = 12
    Const S13 As Long = 17
    Const S14 As Long = 22
    Const S21 As Long = 5
    Const S22 As Long = 9
    Const S23 As Long = 14
    Const S24 As Long = 20
    Const S31 As Long = 4
    Const S32 As Long = 11
    Const S33 As Long = 16
    Const S34 As Long = 23
    Const S41 As Long = 6
    Const S42 As Long = 10
    Const S43 As Long = 15
    Const S44 As Long = 21

    ' Steps 1 and 2.  Append padding bits and length and convert to words
    x = ConvertToWordArray(sMessage)
   
    ' Step 3.  Initialise
    a = &H67452301
    b = &HEFCDAB89
    c = &H98BADCFE
    d = &H10325476

    ' REPLACING FROM HERE
          Dim FileHandle As Integer, FLen As Integer
          Dim xas String(16,0);
          FileHandle = FreeFile
          Open Filename For Binary Access Read As FileHandle
          FLen = Lof(FileHandle)

     Do
         Get #FileHandle, , x

        AA = a
        BB = b
        CC = c
        DD = d
   
        ' The hex number on the end of each of the following procedure calls is
        ' an element from the 64 element table constructed with
        ' T(i) = Int(4294967296 * Abs(Sin(i))) where i is 1 to 64.
        '
        ' However, for speed we don't want to calculate the value every time.
        FF a, b, c, d, x(k + 0), S11, &HD76AA478
        FF d, a, b, c, x(k + 1), S12, &HE8C7B756
        FF c, d, a, b, x(k + 2), S13, &H242070DB
        FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
        FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
        FF d, a, b, c, x(k + 5), S12, &H4787C62A
        FF c, d, a, b, x(k + 6), S13, &HA8304613
        FF b, c, d, a, x(k + 7), S14, &HFD469501
        FF a, b, c, d, x(k + 8), S11, &H698098D8
        FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
        FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
        FF b, c, d, a, x(k + 11), S14, &H895CD7BE
        FF a, b, c, d, x(k + 12), S11, &H6B901122
        FF d, a, b, c, x(k + 13), S12, &HFD987193
        FF c, d, a, b, x(k + 14), S13, &HA679438E
        FF b, c, d, a, x(k + 15), S14, &H49B40821
   
        GG a, b, c, d, x(k + 1), S21, &HF61E2562
        GG d, a, b, c, x(k + 6), S22, &HC040B340
        GG c, d, a, b, x(k + 11), S23, &H265E5A51
        GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
        GG a, b, c, d, x(k + 5), S21, &HD62F105D
        GG d, a, b, c, x(k + 10), S22, &H2441453
        GG c, d, a, b, x(k + 15), S23, &HD8A1E681
        GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
        GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
        GG d, a, b, c, x(k + 14), S22, &HC33707D6
        GG c, d, a, b, x(k + 3), S23, &HF4D50D87
        GG b, c, d, a, x(k + 8), S24, &H455A14ED
        GG a, b, c, d, x(k + 13), S21, &HA9E3E905
        GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
        GG c, d, a, b, x(k + 7), S23, &H676F02D9
        GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
           
        HH a, b, c, d, x(k + 5), S31, &HFFFA3942
        HH d, a, b, c, x(k + 8), S32, &H8771F681
        HH c, d, a, b, x(k + 11), S33, &H6D9D6122
        HH b, c, d, a, x(k + 14), S34, &HFDE5380C
        HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
        HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
        HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
        HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
        HH a, b, c, d, x(k + 13), S31, &H289B7EC6
        HH d, a, b, c, x(k + 0), S32, &HEAA127FA
        HH c, d, a, b, x(k + 3), S33, &HD4EF3085
        HH b, c, d, a, x(k + 6), S34, &H4881D05
        HH a, b, c, d, x(k + 9), S31, &HD9D4D039
        HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
        HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
        HH b, c, d, a, x(k + 2), S34, &HC4AC5665
   
        II a, b, c, d, x(k + 0), S41, &HF4292244
        II d, a, b, c, x(k + 7), S42, &H432AFF97
        II c, d, a, b, x(k + 14), S43, &HAB9423A7
        II b, c, d, a, x(k + 5), S44, &HFC93A039
        II a, b, c, d, x(k + 12), S41, &H655B59C3
        II d, a, b, c, x(k + 3), S42, &H8F0CCC92
        II c, d, a, b, x(k + 10), S43, &HFFEFF47D
        II b, c, d, a, x(k + 1), S44, &H85845DD1
        II a, b, c, d, x(k + 8), S41, &H6FA87E4F
        II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
        II c, d, a, b, x(k + 6), S43, &HA3014314
        II b, c, d, a, x(k + 13), S44, &H4E0811A1
        II a, b, c, d, x(k + 4), S41, &HF7537E82
        II d, a, b, c, x(k + 11), S42, &HBD3AF235
        II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
        II b, c, d, a, x(k + 9), S44, &HEB86D391
   
        a = AddUnsigned(a, AA)
        b = AddUnsigned(b, BB)
        c = AddUnsigned(c, CC)
        d = AddUnsigned(d, DD)

    ' SOME CHANGES HERE
       FLen = Flen - 16
       if FLen <= 0  then exit do
    Loop

   Close FileHandle
   
    ' Step 5.  Output the 128 bit digest
    MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
End Function
0
 
LVL 10

Expert Comment

by:anv
ID: 12176859
check link below for more information

http://www.freesoft.org/CIE/RFC/1321/3.htm
0
 

Author Comment

by:Jimmyx1000
ID: 12177037
Hello Expert

Please can you verify the code with compiler please.
i dont want to be sure it is going to be ok .

thankyou.

0
 

Author Comment

by:Jimmyx1000
ID: 12177065
Hmmm.  

Can you guide me step by step
in how to implement your code above thanks.

start to finish would be nice

thankyou.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12179443
The original MD5() function uses a For..Next loop to read an entire string in steps of 16 bytes. I have replaced the loop with a Do...End Do loop and read directly from a File in 16 bytes chunks, the rest remains unchanged, so it should work exactly as original routine. I don't have a Visual Basic compiler with me, so other expert can make a test.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now