calculating MD5 from binary file

  • Thread starter Thread starter Me
  • Start date Start date
M

Me

Does anyone have a VB.Net sample for calculating the MD5 value from a binary
file? Had it a while ago but formated the drive by accident... :\

J
 
Found the answer(Murphy must be laughing at me) ;) I've cobbled together a
sample using the following solution (I think it's in C#):

http://www.gotdotnet.com/Community/...mpleGuid=78ec88b8-0bb6-4d26-aad4-ddc38d8d6fab

Here are my samples:

Quick and dirty way:

Sub QDMD5(strPath as String)
Dim fs As New FileStream(strPath, FileMode.Open,
FileAccess.Read)
Dim bt As Byte() = New
Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(fs)
Console.WriteLine(BitConverter.ToString(bt))
fs.Close()
End Sub

Long way(may be slightly more readable).

Sub LWMD5(strPath as String)
Dim fs2 As FileStream
Dim bt2 As Byte()
Dim MDCheck As New Security.Cryptography.MD5CryptoServiceProvider

fs2 = File.Open(strPath , FileMode.Open, FileAccess.Read)
bt2 = check.ComputeHash(fs2)
Console.WriteLine(BitConverter.ToString(bt2))
fs2.Close()
End Sub

YMMV :)

Yeah I know meaningful variables would be nice... I'll document it tomorrow.
;) (sorry for the rambling I'm suffering from a NyQuil hangover :) )
 
Hi Me,

Thanks for the code. Someone's just come in asking how to - gues what -
calculate MD5 from a file!!

Cheers,
Fergus
 
Back
Top