how to Encrypt/Decrypt querystring?

Hi Experts,
I need to encrypt/decrypt my querystring in code behind.
And I need to decrypt that querystring in javascript also.

For fetching qurerystring in javascript I am using
<script type="text/javascript">
var str =;
var keyvalArr = str.split('&');
for(var i=0; i<keyvalArr.length; i++){
  var key = keyvalArr[i].split('=');

and in code behind I am using request.querystring

Now I want to encrypt the querysting and it should be accessible in javascript and code behind too.
How to do this?
Johny BravoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What is the point of encrypting a querystring when you use a client-side function to decrypt it?  That (client-side) function will be accessible to every one browsing your page.
Ivo StoykovCommented:
look following sample for code behind. I doubt there is sense to encrypt anything in javascript (at client) because if you could encrypt, somebody could decrypt it ;-)
Ivo Styoykov

public string encryptQueryString(string strQueryString) {
    ExtractAndSerialize.Encryption64 oES = 
        new ExtractAndSerialize.Encryption64();
    return oES.Encrypt(strQueryString,"!#$a54?3");
public string decryptQueryString(string strQueryString) {
    ExtractAndSerialize.Encryption64 oES = 
        new ExtractAndSerialize.Encryption64();
    return oES.Decrypt(strQueryString,"!#$a54?3");

Open in new window

Johny BravoAuthor Commented:
I am creating an XML file depending on the value of querystring.
The table is populated according to the XML file with the use of javascript.So I need to know what is the value of querystring to get that particular XML file.
I don't need to encrypt in javascript,I just want to decrypt in javascript to get the value.

In code-behind I need both encryption/decryption .
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Ivo StoykovCommented:
there is no sense to send encrypted data to be decrypted at client (JavaScript).
There is no difference how it will be sent. At end you'll have plain text which will be visible at client.

As for the traffic, if you'd like to be safe just use SSL (HTTPS).


Ivo Stoykov

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Johny BravoAuthor Commented:
Hi ivostoykov,
What I was thinking was,I will encrypt/decrypt the querystring in code behind.
And as I need to know querystring value t fetch the particular XML,I will decrypt it in javascript also.

But now as per your comment I think that that is not good .

Is there any other way that I will change the querysting that I can know I both code behind and javascript.

Johny BravoAuthor Commented:
I think I was on wrong track.Thanks
Ivo StoykovCommented:
you have encrypt/decrypt functions in JS but they are more for compatibility use rather than for security.

Same for encode/decode pair.


Ivo Sotykov
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.