By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,268 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,268 IT Pros & Developers. It's quick & easy.

MD5 Hash

P: n/a
I'm looking for an example that given any filename as input an MD5-Hash hex
output would be achieved.

Anyone have this?
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
look at:
http://www.vbaccelerator.com/home/NE...32/article.asp

Marcello
www.cantelmosoftware.com

http://xoomer.virgilio.it/cantelmoso.../net/TryMe.zip
"Andy Phillips" <an***********@callatg.com> ha scritto nel messaggio
news:O9**************@TK2MSFTNGP10.phx.gbl...
I'm looking for an example that given any filename as input an MD5-Hash
hex
output would be achieved.

Anyone have this?

Nov 21 '05 #2

P: n/a
On Mon, 16 May 2005 16:16:46 -0700, "Andy Phillips"
<an***********@callatg.com> wrote:
I'm looking for an example that given any filename as input an MD5-Hash hex
output would be achieved.

Anyone have this?


Try this:

Public Function MD5_Hash(ByVal FileName As String) As String
Dim MD5Hasher As MD5
Dim fs As FileStream
Dim hash() As Byte

fs = File.Open(FileName, FileMode.Open)
hash = MD5Hasher.ComputeHash(fs)
fs.Close()
Return BitConverter.ToString(hash)
End Function

I haven't tested it yet, so post back and let me know who it works.

Tibby
Nov 21 '05 #3

P: n/a

"Tibby" <ti*************@hotmail.com> wrote in message
news:33********************************@4ax.com...

same idea, but working code from a thing that i use to check that I have
really downloaded the same file as the author meant...

Imports System.Security.Cryptography

Imports System.IO

Public Class frmMain

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBrowse.Click

If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then

txtFileName.Text = ofd.FileName

End If

End Sub

Private Sub btnGenerateHash_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGenerateHash.Click

Dim fs As FileStream

Dim byt() As Byte

If (New FileInfo(txtFileName.Text).Exists) Then

Try

fs = File.Open(txtFileName.Text, FileMode.Open, FileAccess.Read)

Dim md5 As New MD5CryptoServiceProvider()

byt = md5.ComputeHash(fs)

txtMD5.Text = BitConverter.ToString(byt)

Dim sha1 As New SHA1CryptoServiceProvider()

fs.Position = 0

byt = sha1.ComputeHash(fs)

txtSHA1.Text = BitConverter.ToString(byt)

Catch ex As Exception

MessageBox.Show(ex.Message)

Finally

If (Not IsNothing(fs)) Then fs.Close()

End Try

End If

End Sub

End Class
Nov 21 '05 #4

P: n/a
I've tried using the code but I get too many build errors. I'm a VB6 native
and hurting badly trying to move to DOTNET. I cant figure out where to place
the code in a project with out errors. If you could please throw me a bone.
Maybe insert the code into ??? and place this in a form?? or module or
whatever I'd greatly appreciate it.

Thanks
"stand__sure" <st*********@hotmail.com> wrote in message
news:d6**********@domitilla.aioe.org...

"Tibby" <ti*************@hotmail.com> wrote in message
news:33********************************@4ax.com...

same idea, but working code from a thing that i use to check that I have
really downloaded the same file as the author meant...

Imports System.Security.Cryptography

Imports System.IO

Public Class frmMain

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBrowse.Click

If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then

txtFileName.Text = ofd.FileName

End If

End Sub

Private Sub btnGenerateHash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateHash.Click

Dim fs As FileStream

Dim byt() As Byte

If (New FileInfo(txtFileName.Text).Exists) Then

Try

fs = File.Open(txtFileName.Text, FileMode.Open, FileAccess.Read)

Dim md5 As New MD5CryptoServiceProvider()

byt = md5.ComputeHash(fs)

txtMD5.Text = BitConverter.ToString(byt)

Dim sha1 As New SHA1CryptoServiceProvider()

fs.Position = 0

byt = sha1.ComputeHash(fs)

txtSHA1.Text = BitConverter.ToString(byt)

Catch ex As Exception

MessageBox.Show(ex.Message)

Finally

If (Not IsNothing(fs)) Then fs.Close()

End Try

End If

End Sub

End Class

Nov 21 '05 #5

P: n/a
It works. Thanks tibby. Just had to cut out your diaglogs and textboxs and
get the code in a module correctly. Thanks Agin

"Andy Phillips" <an***********@callatg.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I've tried using the code but I get too many build errors. I'm a VB6 native and hurting badly trying to move to DOTNET. I cant figure out where to place the code in a project with out errors. If you could please throw me a bone. Maybe insert the code into ??? and place this in a form?? or module or
whatever I'd greatly appreciate it.

Thanks
"stand__sure" <st*********@hotmail.com> wrote in message
news:d6**********@domitilla.aioe.org...

"Tibby" <ti*************@hotmail.com> wrote in message
news:33********************************@4ax.com...

same idea, but working code from a thing that i use to check that I have
really downloaded the same file as the author meant...

Imports System.Security.Cryptography

Imports System.IO

Public Class frmMain

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBrowse.Click

If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then

txtFileName.Text = ofd.FileName

End If

End Sub

Private Sub btnGenerateHash_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnGenerateHash.Click

Dim fs As FileStream

Dim byt() As Byte

If (New FileInfo(txtFileName.Text).Exists) Then

Try

fs = File.Open(txtFileName.Text, FileMode.Open, FileAccess.Read)

Dim md5 As New MD5CryptoServiceProvider()

byt = md5.ComputeHash(fs)

txtMD5.Text = BitConverter.ToString(byt)

Dim sha1 As New SHA1CryptoServiceProvider()

fs.Position = 0

byt = sha1.ComputeHash(fs)

txtSHA1.Text = BitConverter.ToString(byt)

Catch ex As Exception

MessageBox.Show(ex.Message)

Finally

If (Not IsNothing(fs)) Then fs.Close()

End Try

End If

End Sub

End Class


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.