Is there any javascript function that can encrypt data: For example i want to use encrypted data in my URL passed by ajax GET request,
http://sample.com/mypage/TDjsavbuydksabjcbhgy
where TDjsavbuydksabjcbhgy an encrypted data equivalent to 12345. Now i want to retrieve that data in PHP by decrypting it, so that i can use the 12345.
Is it possible? or any suggestion on how to do that.
Thanks in advance.
I'm not sure what you would gain by doing encryption in javascript. Your entire routine and encryption key are effectively available to the public. If you are trying to protect against sniffing, you should use SSL.
I think you will have to use SSL to encrypt everything.
You could use AES + Base64, there's a JS aes library at http://www.movable-type.co.uk/scripts/aes.html, should be doable in php as well http://www.movable-type.co.uk/scripts/aes-php.html.
What you are probably looking for is RSA encryption. You generate a key for your server to use which has a public version and a private version. Your javascript will contain the public version which can be used to encrypt the data, and your php will use the private version to decrypt the data.
As a jumping off point, you can start here for javascript public/private key examples: http://shop-js.sourceforge.net/crypto2.htm
And here for the PHP side: http://www.webtatic.com/blog/2009/07/php-public-key-cryptography/