I'm pulling 500 results from a search query to a webservice; I store these in the session for that user so pagnation doesnt cause further calls.
What I want to do is stick the parameters together into one long string and hash them so I have a quick hash to check against.
in php this would look something like...
<?php
$_SESSION["shash"] = md5($_GET['x'] . $_GET['y'] . $_GET['z']);
?>
Done Lazily anyway.
So in C# I have...
#region Session Check
string sCheckStr = rarREF;
string searchCheck = GetMd5Sum(sCheckStr);
if ((Session["schk"].ToString().Length > 0) && (Session["schk"].ToString() == searchCheck))
{ }
else
{
if (searchResults != null) this.mySess.SessionVariables.SearchResults = null;
Session["schk"] = searchCheck;
}
#endregion
And apparently no default MD5 Class built in so I've used one off another site.
#region MD5 Class
static public string GetMd5Sum(string str)
{
// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
#endregion
Which doesn't work properly. rarRef is in the original (public ActionResult Index(string rarREF)) Is there a quicker way, as this needs to be fast. Would Base64 Encoding it do?