Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2060
  • Last Modified:

encrypt javascript code in des with public key and decrypt it in php with private key

i want to DES encrypt javascript code and want to decrypt it in server side using php with a private key.

Please suggest me how to implement this.
0
chrisvee
Asked:
chrisvee
  • 5
2 Solutions
 
gr8gonzoConsultantCommented:
You want to encrypt the Javascript code itself using PHP and then decrypt the code later using PHP again?

Or are you saying you want to use Javascript to encrypt a value and then use PHP to decrypt it?

Any reason you want to use DES specifically?
0
 
chrisveeAuthor Commented:
yes. i want to use Javascript to encrypt a value and then use PHP to decrypt it.

base64 method can be easily decoded. so thats why i am planning to use DES.
0
 
gr8gonzoConsultantCommented:
Also, you mentioned "private key" - are you talking about using public/private key encryption (asymmetric) or symmetric?

Asymmetric is when you have a public certificate that does the encryption and a private key that does the decryption.

Symmetric is when you encrypt and decrypt data using the same password. DES is a cipher that's used in symmetric cryptography, not in asymmetric (at least not to my knowledge).

For Javascript crypto, I'd suggest this library:
https://code.google.com/p/jscryptolib/

For PHP crypt, use mcrypt:
http://php.net/manual/en/book.mcrypt.php
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
gr8gonzoConsultantCommented:
Base64 is not encryption - that is encoding. There is no security around base64. If you don't have a specific need for DES, I would suggest using AES encryption. It's a more common cipher, so you'll have better luck finding specific examples in the future, and you can start with AES-128 and move up to AES-256 if you want even stronger security.
0
 
gr8gonzoConsultantCommented:
Sorry, I linked to the wrong Javascript library. I was trying to link to CryptoJS, not JSCrypto:
https://code.google.com/p/crypto-js/#AES

That should show you the code to encrypt the value in AES (you may need to base64-encode the encrypted value afterwards so that it works with other requests).

The decryption routine can be found here:
http://php.net/manual/en/function.mcrypt-decrypt.php
0
 
Dave BaldwinFixer of ProblemsCommented:
If you are doing this to prevent eavesdropping, SSL/TLS cert and HTTPS is a better way.  That way, any eavedropper won't even know there is something to be encrypted in your response because it is All encrypted.
0
 
gr8gonzoConsultantCommented:
Is there a reason for the B grade instead of the A grade? I gave you exactly what you were asking for...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now