Hash codes are useful to compare large blocks of text, among other things. Do the following to get a simple has code for a block of plain text:
public string GetHashCode(string plainText)
{
byte[] saltBytes = new byte[] { 1, 2, 3, 4 };// Convert plain text into a byte array.
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);// Allocate array, which will hold plain text and salt.
byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length];// Copy plain text bytes into resulting array.
int i = 0;
for (i = 0; i <= plainTextBytes.Length – 1; i++)
{
plainTextWithSaltBytes[i] = plainTextBytes[i];
}// Append salt bytes to the resulting array.
for (i = 0; i <= saltBytes.Length – 1; i++)
{
plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];
}HashAlgorithm hash = new MD5CryptoServiceProvider();
// Compute hash value of our plain text with appended salt.
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);
// Create array which will hold hash and original salt bytes.
byte[] hashWithSaltBytes = new byte[hashBytes.Length + saltBytes.Length];// Copy hash bytes into resulting array.
for (i = 0; i <= hashBytes.Length – 1; i++)
{
hashWithSaltBytes[i] = hashBytes[i];
}// Append salt bytes to the result.
for (i = 0; i <= saltBytes.Length – 1; i++)
{
hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
}// Convert result into a base64-encoded string.
string hashValue = Convert.ToBase64String(hashWithSaltBytes);// Return the result.
return hashValue;
}