Can "Javascript" decrypt PHP encrypted data?

When I normally return Ajax / JSON from PHP, Javascript gets it and stores it inside a variable, like this: var myJSON = ajaxReturnedJSON;

Then Javascript reads it.

I'm very curious to know if php encrypts json:

echo json_encode($encrypted_data); //using some key like: "abc123"

      

  • Then, can I Javascript

    decrypt it back with the same key?
  • Is there a common method encrypt/decrypt

    between php and js?

Note . I understand what key

will render on the JS side, but I can also use JS Obfucators for hex

whole characters, all JS file

. So more or less it will protect, not just / nothing.

Welcome to any ideas and discussions.

+3


source to share


1 answer


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

It's usually pretty pointless, though if this Javascript is running in the browser. Encryption is used to hide information from someone. There are three parties to the server-client script: web server, browser / user, third parties. Now:



  • You don't need to hide information from the web server because you are.
  • You can't hide information from the browser / user, from what point? Just don't display 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 can hide information from the prying eyes of third parties (men in the middle, etc.), but there is already a better solution for that: SSL / TLS. Additionally, if you send all the information needed to decrypt the data to the client, third parties can also intercept this and decrypt the data just like the client.
+3


source







All Articles