I would like to know if it is possible to decrypt the JavaScript encrypted text (which is encrypted using JavaScript's btoa function), using PHP.
2 Answers
Have a look at base64_decode().
JavaScripts btoa() just encodes a string using Base64. The PHP functions for that are base64_encode() and base64_decode().
When I use window.btoa(String) to encode (not encrypt) text and send it over to the server side via AJAX, I find that the client-server exchange has resulted in plus signs ('+'), in the encoded text, being replaced by spaces (' ').
To get the text back to proper encoding in PHP, I've had to use string transform like so:
$clean = strtr( $_POST['ajax-text'], ' ', '+');
$ascii = base64_decode( $clean );
1 Comment
deltab
Sounds like you've sent the encoded text in the query string of a URL. You should encode it using
encodeURIComponent before inserting it.