Link to home
Start Free TrialLog in
Avatar of Johny Bravo
Johny Bravo

asked on

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 = window.location.search.substring(1);
var keyvalArr = str.split('&');
for(var i=0; i<keyvalArr.length; i++){
  var key = keyvalArr[i].split('=');
  if(key[0]=='userid'){
    alert(key[1]);
      break;
  }}
 
 
</script>

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?
Avatar of sybe
sybe

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.
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 ;-)
HTH
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

Avatar of Johny Bravo

ASKER

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 .
ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

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

Same for encode/decode pair.

HTH

Ivo Sotykov