8

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.

2
  • 1
    Why wouldn't encrypting the querystring offer security, assuming that it was done properly? Commented Sep 29, 2009 at 14:26
  • 1
    Luke, I should have instead said, I'm not looking for "security." I just wanted to avoid a lot of people being focused on security. Commented Sep 29, 2009 at 15:05

2 Answers 2

2

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

string encoded = Convert.ToBase64String(Encoding.Unicode.GetBytes(myQueryStringValue));
Sign up to request clarification or add additional context in comments.

2 Comments

Note that this solution doesn't offer security - only obfuscation. (Security by obscurity is not). However, in the OP's case it seems like he's mostly interested in obfuscation, rather than security, so this would probably be a good solution, as long as you UrlEncode to the returned string.
That is why I posted this answer. If he really needs security this would be a poor answer.
1

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?

1 Comment

Hashing is different from encryption.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.