Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "Javascript" Decrypt the Data, Encrypted by PHP?

When I normally return the Ajax/JSON from PHP, the Javascript get it and stores it inside a variable, like: var myJSON = ajaxReturnedJSON; Then Javascript read it.

I'm seriously curious to know if, php encrypts the json:

echo json_encode($encrypted_data); //using some key like: "abc123"
  • Then, can Javascript decrypt it back by using same key?
  • Is there any common encrypt/decrypt method between php and js?

Note: I understand key will be visible at JS side but i can also use JS Obfucators to hex the whole characters, whole JS file. So more or less it will protect, rather then plain/nothing.

Welcome to any ideas and discussions.

like image 721
夏期劇場 Avatar asked Aug 14 '26 14:08

夏期劇場


1 Answers

Sure. Encryption and decryption algorithms are just mathematical operations which can be performed in virtually any programming language. Javascript being a programming language you can implement any decryption algorithm in it you need.

This is typically pretty pointless though if this Javascript is running in the browser. Encryption is used to hide information from somebody. In a server-client scenario, there are three parties: web server, browser/user, third parties. Now:

  • You don't need to hide information from the web server, because that's you.
  • You cannot hide information from the browser/user, since what's the point? Just don't output the information in the first place if you need to hide it. If the browser/Javascript can decrypt the information, so can the user, so it's not hidden.
  • Transport encryption may hide the information from the prying eyes of third parties (men in the middle and such), but for that there's already a better solution: SSL/TLS. Also, if you're sending all the information needed to decrypt data down to the client, third parties can intercept this as well and decrypt the data just like the client.
like image 94
deceze Avatar answered Aug 17 '26 04:08

deceze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!