?
Solved

GetHashCode of string return different values on different OS

Posted on 2011-04-30
2
Medium Priority
?
628 Views
Last Modified: 2012-05-11
Hi,

I have a vb.net 3.5 desktop application. This uses couple of .net dll which are also written in vb.net 3.5. These dll have common funtions. Now I wanted that these dlls should not be used by other people where this desktop app is installed. So whenever I create instance of this dll, I pass a hard-coded string as "MyApp_Protected_2000". This string is passed from my win form to the constructor of the dll. The constructor of the dll uses .GetHashCode to get the hashcode of this string. I compare this hashcode return value which I have pre-generated in development environment (XP with 32-bit OS) and compare it like this:

========= Class Code ===================
If strValidate.Trim.GetHashCode <> -5999234 then      
      Throw new exception "Unauthorized User"
Endif
========================================

This way I ensured that noone can use this dll.

But now I find that if this app is used on Windows 7 (64-bit), the GetHashCode returns different value other than -5999234  for the same string "MyApp_Protected_2000".

a. Why is this so? And how can I resolve this issue? What can I do to ensure that the string returns same value no matter what CLR version and OS versiion?

b. Or should I find the encrypted value of "MyApp_Protected_2000" in design-time and compare with that? The only problem I see here is that the encrypted value would have some special chars and I am afraid that might break the app. Also now I have doubt that even the encryption function may return different values on 32-bit and 64-bit OS.


Please help.

Regards,
MI



0
Comment
Question by:vj_mi
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 35497248
0
 
LVL 10

Assisted Solution

by:WayneATaylor
WayneATaylor earned 1000 total points
ID: 35497254
Hashcode do vary by versions, as is explained in the MS article.

http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx

I guess the only way round this would be to write your own code for creating the hashes.

Wayne
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

864 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