views:

1649

answers:

3

Server side we can authenticate the user but I want security of data when ajax or JQuery sends the data. Like on client side someone can only see the parameters of any call in encrypted format. So how do I do this. I have seen this scenario on this site.

EDIT

we can ignore to encrypt data when it comes form server. But atleast at sending time it is required. see the example on this site in your preference setting the checkboxes for notification. one can watch request by using firebug add-on in Mozilla firefox.

+3  A: 

You can't.

If the browser (i.e. JavaScript) is supposed to read/work with the values, they have to be clear text. Any encryption/scrambling scheme you might come up with will be inherently broken since JavaScript itself must be able to decrypt/unscramble the data, and therefore anyone with a medium amount of wit can access the source code will be able to figure it out.

You can do SSL requests to encrypt the server connection, hiding the data from third parties.

Tomalak
Using SSL is the best choice, but encryption can be done, but it adds complexity that may not be worth the risk, esp since ajax can hide a great deal of what is happening.
James Black
@James Black: But it's still not *secure*, and it never will be. Hiding stuff a little bit and adding a few hoops is pointless.
Tomalak
+3  A: 

You could encrypt the data using some libraries, such as http://home.versatel.nl/MAvanEverdingen/Code/ but as was mentioned above it can be reverse engineered by someone using a debugger to see the key.

In order to do this securely you would need to have a public key for the server, and it would use this to get the symmetric key from the server, which encrypted the key with it's private key.

javascript then decrypts the symmetric key with the public key.

Now, this symmetric key is used to encrypt data.

If the data is small enough then you can use the public key to encrypt data, but there is size limits based on the size of your public key.

So, yes, you can do it, but it can be reverse-engineered.

James Black
+1  A: 

If your problem is just encrypting the data sent by the user, use SSL on the server so that connections to it are encrypted. Your AJAX url would be https://myserver.com/Ajax/Endpoint or whatever.

swilliams