Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have string records of about 50 characters each in length (built from several other fields) from which I want a smaller hex key. This resultant key must be reproducable given the same string and algorithm to encode with.

I tried the SHA-1 and MD5 and each time I get (the expected) different encrypted string for the same original value. I have thousands of these records and I need to search thru these and hence the need to make this 50 byte string into a smaller faster searchable hex key.

I appreciate any advice.

Thanks in advance.
Posted
Updated 2-May-10 6:23am
v2

It's built-in functionality in the .Net framework.
GetHashCode[^] will do that.
There is however no guarantee that different versions of the framework will produce the same hash.
The keys are used by the framework to create and index hash collections.
Note that in .Net if 2 strings have the same content, they are actually the same object.
 
Share this answer
 
v2
I'd be tempted to use the SHA256 cryptography classes. You can use it like this:
public static byte[] CalcHash(this string value)
{
  if (string.IsNullOrEmpty(value))
    return new byte[0]{};
  byte[] calc = new ASCIIEncoding().GetBytes(value);
  SHA256 unmanaged = new SHA256Managed();
  return unmanaged.ComputeHash(calc);
}
 
Share this answer
 
Hi

are you trying to hash or encrypting something?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900