Solved

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

Posted on 2013-07-01
7
1,637 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
  • 5
7 Comments
 
LVL 34

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 34

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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 34

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 34

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 82

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 34

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now