View Full Version : Md5 Vb Howto Needed
cselik
01-07-2004, 10:58 AM
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 (http://www.planet-source-code.com/URLSEO/vb/scripts/ShowCode!asp/txtCodeId!735/lngWid!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
Rocko
01-08-2004, 12:28 AM
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:
#compile dll "hash.dll"
#include "win32api.inc"
The replace the line:
Function GetHash(ByVal sFileName As String, ByVal pbHash As Byte Ptr) As Long
with
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 :
Declare Function GetHash LIB "Hash.dll" (sFileName As String, ByRef pbHash As Byte) As Integer
Example call:
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
cselik
01-08-2004, 03:59 PM
thank you rocko
i've got the dll, delclared the function (it had to be ucase: GETHASH) and types had to be de-remarked:
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
Declare Function GETHASH Lib "hash.dll" (sFileName As String, ByRef pbHash As Byte) As Integer
...vb 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 (sig2dat:///|File:testfile.bin|Length:128786 Bytes, 125KB|UUHash:=7AutXhwScpWFibHLX+S5oe0I/v8=|)
testfile.bin ed2k (http://ed2k://|file|testfile.bin|128786|1d0b397f671f7b285d71ba0b96d0b229|/)
Rocko
01-08-2004, 06:40 PM
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
cselik
01-08-2004, 08:11 PM
I added byval to sFileName and called
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. (http://www.hszk.bme.hu/~cd197/Programzas/VBasic/Dir2html/hashdll/index.html)
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 (http://dir2html.tk/) 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?
Powered by vBulletin® Version 4.2.3 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.