Solved

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

Posted on 2013-07-01
7
1,734 Views
Last Modified: 2013-07-25
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
Comment
Question by:chrisvee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39291333
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
 

Author Comment

by:chrisvee
ID: 39291356
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
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 400 total points
ID: 39291360
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39291367
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
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39291409
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
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 39291661
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
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39354946
Is there a reason for the B grade instead of the A grade? I gave you exactly what you were asking for...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question