0

I am passing an encrypted string using URL and now I can decrypt it because the encrypted string contains + symbol. How to bypass this,

I am using AES encryption in Javascript.

My code is,

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>

window.location.href = "check.php?encr="+encodeURIComponent(CryptoJS.AES.encrypt(80,"qJB0rGtIn5UB1xG03efyCp"));

encryption string is U2FsdGVkX184sTDp%2BB%2Bgpn07shpb6lqRzqTh4BLOMj4%3D

Decryption code is,

var decrypted = CryptoJS.AES.decrypt("<?php echo urldecode($_GET["encr"]); ?>", "qJB0rGtIn5UB1xG03efyCp");

How can i avoid + symbol. Is there any solution.

2 Answers 2

1

Values in $_GET are already URL-decoded. Do not decode them again, that's what's causing you issues. Simply echo $_GET['encore'] will do.

Note that you should also json_encode the value to ensure you're outputting proper Javascript syntax:

.decrypt(<?php echo json_encode($_GET['encr']); ?>)
Sign up to request clarification or add additional context in comments.

1 Comment

Having said that I'd question the core premise of what you're doing with encryption there, but I'm reserving judgement on that...
0

I have got the answer

encryption,

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>

window.location.href = "check.php?encr="+CryptoJS.AES.encrypt(80,"qJB0rGtIn5UB1xG03efyCp");

decryption,

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>

$q = urlencode($_GET["encr"]);
$q = str_replace("+", "%2B",$q);
$q = urldecode($q);

var decrypted = CryptoJS.AES.decrypt("<?php echo $q; ?>", "qJB0rGtIn5UB1xG03efyCp");

Comments

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.