Your Ad Here Your Ad Here
Results 1 to 5 of 5

Thread: Md5 Vb Howto Needed

  1. #1
    cselik's Avatar Poster
    Join Date
    Jan 2004
    Location
    Srbija
    Posts
    85
    i am doing a small vb project http://dir2html.tk and i want to add a feature for p2p world users to instantly genarate hashes for p2p applications, (as an alternative to http) for all files in dir with 1 click.

    i tried
    http://www.planet-source-code.com/URLSEO/v...3;5/anyname.htm
    but it always gets the hash wrong

    i also tried ksig and sig2dat src codes, they are doing the job.

    what i need now is a how to make a dll file that does the hash, out of those source codes and info on how to implement it in my vb tool. (credits will be naturaly included)

    thanx in advance

  2. File Sharing   -   #2
    Rocko's Avatar Poster
    Join Date
    Oct 2002
    Location
    Perú
    Age
    35
    Posts
    83
    Download KLExtensions source from www.o-townnet.tk. Then get PowerBASIC Windows compiler 7 from eMule. There is a file called hash.inc in the sources. Add to the biginning of the file:
    Code:
    #compile dll "hash.dll"
    #include "win32api.inc"
    The replace the line:
    Code:
    Function GetHash(ByVal sFileName As String, ByVal pbHash As Byte Ptr) As Long
    with
    Code:
    Function GetHash(ByVal sFileName As String, ByVal pbHash As Byte Ptr) Export As Long
    Then compile. It will generate a dll file called hash.dll.

    The Visual Basic Declare should look as :
    Code:
    Declare Function GetHash LIB "Hash.dll" (sFileName As String, ByRef pbHash As Byte) As Integer
    Example call:
    Code:
    Dim sFile as String
    Dim bHash(1 To 20) as Byte
    sFile = "MyFile.dat"
    GetHash(sFile, bHash(1))
    To encode to Base64 there is a function called Encode_BASE64 that do the job.

    Rocko

  3. File Sharing   -   #3
    cselik's Avatar Poster
    Join Date
    Jan 2004
    Location
    Srbija
    Posts
    85
    thank you rocko
    i've got the dll, delclared the function (it had to be ucase: GETHASH) and types had to be de-remarked:

    Code:
    TYPE MD5_CTX
      dwState(3)  AS LONG 'state (ABCD)
      lCount(1)   AS LONG 'number of bits modulo 2^64 (lsp first)
      bBuffer(63) AS BYTE 'input buffer
    END TYPE  
    .... in vb module
    Code:
    Declare Function GETHASH Lib "hash.dll" (sFileName As String, ByRef pbHash As Byte) As Integer
    ...vb code
    Code:
        sFile = "d:\testfile.bin"
        txtRez.Text = GETHASH(sFile, bHash(1))
    
    Open "bytes_out.txt" For Output As #2
        For i = 1 To 20
            txtHash.Text = txtHash.Text + Str$(bHash(i))
            Print #2, bHash(i)
        Next
    Close (2)
    I don't know where to read the value
    GETHASH returns 0
    bHash(i) 's are all zeros after calling

    and when i suceed, how do i make sig2dat:// and ed2k:// links like from sig2dat does (hashes are different)?

    testfile.bin sig2dat

    testfile.bin ed2k

  4. File Sharing   -   #4
    Rocko's Avatar Poster
    Join Date
    Oct 2002
    Location
    Perú
    Age
    35
    Posts
    83
    The function returns non zero on success and zero when it fails. Maybe the parameters aren't passed correctly to the function.
    Add the DebugPrint MACRO from the main.bas file to hash.inc then add a line at the begining of GetHash like DebugPrint("sFileName: " + sFileName)
    Use DebugView from sysinternal (www.sysinternals.com) to see the output. The output should display the filename your are passing to the function.

    Try it and tell me what happen.

    Rocko

  5. File Sharing   -   #5
    cselik's Avatar Poster
    Join Date
    Jan 2004
    Location
    Srbija
    Posts
    85
    I added byval to sFileName and called
    Code:
     * *Private Declare Function ENCODE_BASE64 Lib "hash.dll" (ByRef pbInBuf As Byte, ByVal lBufLen As Long) As String
    the lBufLen is 20

    btw i ve uploadded everything here.

    everything works now. i'll leave the working forms and sources up, if anyone else is interested in how to use md5 in visual basic.

    i also compiled dir2sig which is optimized for fast hash making, rather than linking to raw data.

    thanx again for helping me with this, one more question, how to make ed2k hashes?

Bookmarks

Posting Permissions

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