this could be made better, with more robust value checking etc. but should do the job:
create the function:
Code:
public string hash_hmac(string message, string key)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(key);
System.Security.Cryptography.HMACMD5 hmacmd5 = new System.Security.Cryptography.HMACMD5(keyByte);
byte[] messageBytes = encoding.GetBytes(message);
byte[] hashmessage = hmacmd5.ComputeHash(messageBytes);
string hashmessageString = "";
for (int i = 0; i < hashmessage.Length; i++)
{
hashmessageString += hashmessage[i].ToString("X2"); // hex format
}
return (hashmessageString);
}
and use it with:
Code:
int forum_id = 5;
int user_id = 16;
if (forum_id == null)
forum_id = 0;
string hash = hash_hmac(String.Format("{0)-{1}", user_id, forum_id), "stupidASP").Substring(0, 10);
string link = String.Format("http://www.beex.co.uk/{0)/{1}/{2}", user_id, forum_id, hash);