views:

4089

answers:

4

Hi,

I'd like to encrypt in javascript and then decrypt in Php.

There are RSA implementations for javascript and php but they are not compatible. I cannot decrypt in Php correctly what I had encrypted with javascript.

Does anyone know a library/code that will work both with javascript and Php?

Thanks.

+1  A: 

If you set up your server to use SSL then you can have encrypted transmission via ajax using https. That is probably the best way to encrypt data between javascript and php. If you want to make it yourself there is a big chance you will screw up somewhere and the system wont be secure.

Google on how to set up https for your server.

Marius
A: 

I assume you have a valid reason to do that other than to do https yourself, so I'd say that if you stick to the standards you should be able to easily decrypt with whatever technology supports these standards : ie it should work

For example if you encrypt your data in PKCS#7 format, be sure that your php library knows that the input data is PKCS#7.

Also be sure that your encryption key is not scrambled between server and client. Did you try to decrypt your data with your javascript library ?

Hope this can help...

Sébastien Nussbaumer
A: 

Maybe you can help by putting the code you're using for both js and php.

Also, maybe you could be more specific on why you need to use js and php. Maybe you could use only php, and AJAX (to query the same php function) where you were using js.

ign
+1  A: 

Hi,

Here is an JavaScript RSA encryption library: http://www.ohdave.com/rsa/

And I think you could use something like this class to decrypt the generated encrypted string - http://www.phpclasses.org/browse/package/4121.html

Let me know if you manage get this work together, as I am myself looking into this subject (I actually found this post looking for this answer myself :P ) .

Edit: Look, I've also found this - http://www.sematopia.com/?p=275 - seems related to the previous two as well...

Hope this helps, Constantin TOVISI

titel