My programming knowledge is not very good. So here I discussed query string and route data security. Please review my approach and tell me am I thinking right way.
Often we work with query string and route data pass to controller action. So user can edit those data. For security purpose I do not allow to user edit route and query string data.
So I thought i will create a hash using those query string and route data and append that hash to end of URL.
- Is my thinking correct?
- Should I hash or encrypt query string and route data?
- Which one will be best...hashing or encrypt query string and route data?
This is the way I am doing it now. Here is bit code snippet:
@Html.ActionLink("Test", "Index", new { page = 1, q = Utility.HashData("Hello") })
public static class Utility
{
public static string HashData(string input)
{
string retdata="";
string salykey = "!xcorb@sinon_";
byte[] inputBytes = Encoding.UTF8.GetBytes(string.Concat(input, salykey));
SHA512Managed sha512 = new SHA512Managed();
byte[] outputBytes = sha512.ComputeHash(inputBytes);
string b64 = Convert.ToBase64String(outputBytes);
b64 = b64.Replace('+', '-');
retdata = b64.Replace('/', '_');
return retdata;
}
}
I am hashing data hello and now URL look like http://localhost:61151/Home/Index/1?q=NhX4DJ0pPtdAJof5SyLVjlKbjMeRb4-sf933-9WvTPd309eVp6AKFr9-fz-5Vh7puq5IDan-ehh2nnGIawPzFQ%3D%3D
Is it ok?
I just hash Hello and now see how big hash has been generated. So when I will hash many query string and route data together then my hash data will be huge. So if it will be huge that may cause an issue because the URL length must has some limitation....am I right?
- Can I shorten hashing data length? If possible then which hashing algorithm I should use?
Please discuss my points and drive me to right direction. Thanks.