Encrypt in javascript then decrypt in php

ocsurf
ocsurf used Ask the Experts™
on
I'm trying to find a way to encrypt something in javascript and decrypt it in php. anyone come across something like this. Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi ocsurf,
Here is the problem with that, you're going to have to embed some type of encryption key in the javascript routine which will make decrypting the same text rather trivial by anyone. Have you considered a hash?

For example if this is a password related issue, you can MD5 the password, send it to the server and compare to the password in a database that is also md5 hashed. Make sense? Which is completely irreversible.

-Brian

Author

Commented:
Yea i thought and tried that. but the problem is we are logging into a ldap server and don't have access to the passwords.
Senior Performance Engineer
Commented:
As brian said, anything in javascript will be seen by the user.  Simple fact.  If you are looking for php encryption then there are lots of samples of code that could be used.  There are dozens of freely available scripts out there, however, they are all opensource, and chances are they could be decrypted.  However, it also depends on how secure your site is.  If you utilize ssl, along with authentication and encryption then you should be looking at a pretty sound, but not perfect system to rely on.  Always patch your code, and operating system along the way to ensure integrity of the data.
There is really no secure way to encrypt data on client side.

Commented:
Do you really need to encrypt in javascript?  

Without knowing the specifics of your task, may i suggest that you enter the string that you want encrypted into a html form, then using the POST method, send it to a php page for encryption and comparison against your reference encrypted string.

This method would keep prying eyes out of your encryption process, as it would be handled via your php script.

Remember, it is possible to automatically send forms if this is what you'd like to do.

If you can clarify your task, then i can perhaps help further..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial