473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

MD5 Hash

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
5 2892
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Murali | last post by:
I have a requirement where I have to use two unsigned ints as a key in a STL hash map. A couple of ways to do this is 1. create a struct with two unsigned ints and use that as key (write my own...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
18
by: beginner | last post by:
Hi All. I'd like to do the following in more succint code: if k in b: a=b else: a={} b=a
5
by: Jeff | last post by:
Lets say we have what I would call a "hash": var HASH =new Array(); HASH='first'; HASH='second'; HASH='third'; I'd like to return that as JSON data. Is there a direct way to do that?
1
by: sixtyfootersdude | last post by:
Good Morning! I am a perl newbie and I think that I am struggling with references. I have an array of references to hashes which I am trying to print. This is what I have: for(my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.