Solved

Is GetHashCode for a file unique?

Posted on 2006-07-09
4
723 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
Recommendation vb6 to vb.net or others 14 104
Definitions and default visual studio colors 5 58
fso.FolderExists("\\server\HiddenFolder$") 4 46
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now