Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MD5 File Hash
#1
Hi....

Is there a builtin (or any other way) way of creating MD5 Hash from a file (not a string) ?
I want to upload some files but want to generate MD5 for them so I can check their integrity once fully uploaded.

Appreciate the help.

Regards
VBN
#2
1. This can be used with small files, maybe <10MB. For big files may be not enough memory.
Macro Macro1426
Code:
Copy      Help
str s.getfile("$qm$\qm.exe")
str md5.encrypt(2|8 s)
out md5

2. This can be used with files of any size.
Macro Macro1431
Code:
Copy      Help
str s.FileMD5("$qm$\qm.exe" 1)
out s

For 2 you need this function. Create it as member function.
Member function str.FileMD5
Code:
Copy      Help
function $file [flags] ;;flags: 1 hex

;Calculates MD5 hash of a file and stores into this str variable.
;Error if fails.

;EXAMPLE
;str s.FileMD5("$desktop$\test.txt" 1)
;out s


type MD5_CTX i[2] buf[4] !in[64] !digest[16]
dll- cryptdll
,MD5Init MD5_CTX*context
,MD5Update MD5_CTX*context !*data dataLen
,MD5Final MD5_CTX*context

__HFile f.Create(file OPEN_EXISTING GENERIC_READ FILE_SHARE_READ)

str b.all(4096 2)
int nr
MD5_CTX c
MD5Init &c

rep
,if(!ReadFile(f b 4096 &nr 0)) end _s.dllerror
,if(!nr) break
,MD5Update &c b nr

MD5Final &c
this.fromn(&c.digest 16)
if(flags&1) this.encrypt(8)

err+ end _error
#3
Thanks a lot...I will try this out...

My files are around 150-200 MB in size !


Forum Jump:


Users browsing this thread: 1 Guest(s)