Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encrypt query strings in asp.net?

How do I encrypt query strings in aspx.net?

P.S. I realize that this does not offer security. I'm just looking to obfuscate a puzzle.

P.P.S Though I marked CKret's answer as the correct one (for the question as worded I believe his is the most correct answer). However, for myself, I'm just going to try ChoasPandion's alternative to encryption. If I needed more security I'd look at CKret's or Ian's.

like image 451
user179700 Avatar asked Sep 29 '09 14:09

user179700


2 Answers

Don't bother encrypting it. Just convert it to a base 64 string.

string encoded = Convert.ToBase64String(Encoding.Unicode.GetBytes(myQueryStringValue));
like image 110
ChaosPandion Avatar answered Oct 05 '22 03:10

ChaosPandion


If you trying to hide your product Id's and things like that, then why not just use Encryption?

I guess what you want to do, is to stop people editing the query string to get different results. The simple way to do this, is to add a Hash of the query string to the query string, and have some base-page functionality check that the hash is correct for the request, identifing tampered query strings.

See Prevent query string manipulation by adding a hash?

like image 42
Dead account Avatar answered Oct 05 '22 02:10

Dead account