20

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 2

54

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().

Sign up to request clarification or add additional context in comments.

2 Comments

This is a comment not an answer
@Sam, what's the answer then?
6

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

Sounds like you've sent the encoded text in the query string of a URL. You should encode it using encodeURIComponent before inserting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.