Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error on parsing JSON from php file #6

Closed
alaksandarjesus opened this issue Aug 31, 2015 · 3 comments
Closed

Getting error on parsing JSON from php file #6

alaksandarjesus opened this issue Aug 31, 2015 · 3 comments

Comments

@alaksandarjesus
Copy link

I am getting JSON error while i pass data from php file.
HTML

   <script src="cryptojs-aes-php-master/example/aes.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
  <script src="cryptojs-aes-php-master/aes-json-format.js"></script>

PHP File

$encodeanswer[]=htmlentities(cryptoJsAesEncrypt($answer,"123"))

JS File

console.log(value);

//{"ct":"9i4gxztr7W7W0sPFKo1SKA==","iv":"5fba99d002577c64ce4421a979d49f40","s":"fe836ae24c8ca962"}

var parsedvalue = value.replace(/&quot;/g,'"')
console.log(parsedvalue);

//{ ct: "nPR3gyDA5Q6Qra1Py9GtAA==", iv: "7e10905af0f4d0ba3fb2cfeb5d77ae8e", s: "ee20cfb01b5b25b6" }

console.log(JSON.parse(CryptoJS.AES.decrypt(parsedvalue,"123", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8)));

//SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

Note: I tested your example and it populating data in input box.

@brainfoolong
Copy link
Owner

Remove htmlentities and value.replace.
Furthermore i don't really understand your way to go here. You encrypt data in PHP, than you replace htmlentities, than you replace it back on JS side, than you try to decrypt it AND you try to parse it, the decrypt already do the parse for you.
The real way is: PHP encrypt, JS decrypt, without any step between, no extra htmlentities, no extra JSON.stringify or JSON.parse

@alaksandarjesus
Copy link
Author

Hi. Thanks for reply. I cleared off the error.  I  php file its key and phrase and js file its phrase and key. Why this jnverted combination? 

Alaksandar
+91-9952762769

From:"Roland Eigelsreiter" notifications@github.com
Date:Mon, 31 Aug, 2015 at 10:38
Subject:Re: [cryptojs-aes-php] Getting error on parsing JSON from php file (#6)

Remote htmlentities and value.replace and it will work. Your pasted console.log output also is not correct, it doesn't show the htmlentites encoded string.


Reply to this email directly or view it on GitHub.

@brainfoolong
Copy link
Owner

Em... Don't know, never thought about that :)
I close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants