Solved

Is GetHashCode for a file unique?

Posted on 2006-07-09
4
730 Views
Last Modified: 2012-05-05
I'm using the following example to get the hash code for a file.  Is this hash code unique or could there be instances of overlapping?  If it's the later (instance of overlapping) help me understand how it occurs or if it's a rarity.

        OpenFileDialog1.FileName = ""
        OpenFileDialog1.ShowDialog()

        If OpenFileDialog1.FileName = "" Then Exit Sub

        Dim File_Stream As New System.IO.StreamReader(OpenFileDialog1.FileName)
        Dim File_Hash As Integer = File_Stream.ReadToEnd().GetHashCode()

        RichTextBox1.Text = File_Hash

        File_Stream.Close()
        File_Stream = Nothing
0
Comment
Question by:IUFITS
  • 2
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 17069614
it is a rarity, but collisions can occur.  It only returns a 32-bit value, so there are only 4+ billion unique hash values.

http://msdn2.microsoft.com/en-us/library/system.string.gethashcode.aspx
0
 
LVL 3

Author Comment

by:IUFITS
ID: 17072665
Thanks for the answer.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 17072769
Thanks for the points.  Glad I could help.

A much better hash alternative woulld be SHA-2/SHA160, SHA256, SHA1024.

MD5 is ok for non-sensitive applications, but NIST has put it on a "don't use for criticatl applications" list.
0
 
LVL 3

Author Comment

by:IUFITS
ID: 17072817
Very good, thanks for the additonal info!  :)  I'll keep that in mind.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question