Comments (16)
Please post all code, without knowing the "some_encrypted_data" and "some_data" i cannot help you.
from cryptojs-aes-php.
I'm sorry, you're right, here comes the code:
private function cryptoJsAesEncrypt($passphrase, $value)
{
$salt = openssl_random_pseudo_bytes(8);
$salted = '';
$dx = '';
while (strlen($salted) < 48) {
$dx = md5($dx.$passphrase.$salt, true);
$salted .= $dx;
}
$key = substr($salted, 0, 32);
$iv = substr($salted, 32,16);
$encrypted_data = openssl_encrypt(json_encode($value), 'aes-256-cbc', $key, true, $iv);
$data = array("ct" => base64_encode($encrypted_data), "iv" => bin2hex($iv), "s" => bin2hex($salt));
return json_encode($data);
}
private function getTopClanToonsCount()
{
$sql = "SELECT COUNT( t.game_id ) AS toon_amount, t.toon_clan
FROM toon t
WHERE t.deleted =0
AND t.toon_clan != ''
GROUP BY t.toon_clan
ORDER BY toon_amount DESC
LIMIT 5";
$stmt = DB::getInstance()->prepare($sql);
$stmt->execute();
$clanCount = $stmt->fetchAll();
if (is_array($clanCount))
{
return $this->cryptoJsAesEncrypt('test123', $clanCount);
}
return null;
}
function getTopClanToons(){
$http.post("../some_url.php?action=getTopClanToonsCount").success(function(data){
var CryptoJSAesJson = {
stringify: function (cipherParams) {
var j = {ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)};
if (cipherParams.iv) j.iv = cipherParams.iv.toString();
if (cipherParams.salt) j.s = cipherParams.salt.toString();
return JSON.stringify(j);
},
parse: function (jsonStr) {
var j = JSON.parse(jsonStr);
var cipherParams = CryptoJS.lib.CipherParams.create({ciphertext: CryptoJS.enc.Base64.parse(j.ct)});
if (j.iv) cipherParams.iv = CryptoJS.enc.Hex.parse(j.iv)
if (j.s) cipherParams.salt = CryptoJS.enc.Hex.parse(j.s)
return cipherParams;
}
}
console.log(JSON.parse(CryptoJS.AES.decrypt(data, "test123", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8)));
//$scope.topClanToonsCount = JSON.parse(CryptoJS.AES.decrypt(data, "test", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8));
//$scope.topClanToonsCount = data;
});
};
I hope this will help you... and finally me ;)
from cryptojs-aes-php.
This is a php result after the cryptoJsAesEncrypt:
"{\"ct\":\"OBPmdQVbGuxXVl7MBZCntJwVnDFWnyqIif2B1YyH7BVn4eROzq4i0cus5g3+ZPDTBQbcSe+blmYsc9p7VYb98koVUy06qjrLXr9IPjt9uR\\\/o4aFWd1tdlLQHvtE90D+b\",\"iv\":\"ab044b14232442e4e48f06c195e3b7b4\",\"s\":\"39b096acaba76884\"}"
from cryptojs-aes-php.
What data is in data
of the JS callback, do a console.log(data)
and post the result.
from cryptojs-aes-php.
"{\"ct\":\"dxZkCuq\\\/H7YqQs3E5lrs9ZZ2c9M3O5TCL1Bdtnm\\\/1mkOyEVUOtNk8ZVNPnqp1Ca966dRjOV9k4FT+z7TpEmeYFZv2I1L+q6fWXIIQQIV\\\/m4RiA2V8MF4VEq7y5QBpteN\",\"iv\":\"5c0757952300fe019196d02a830c0af2\",\"s\":\"0c4a63c4dd46ac5b\"}"
from cryptojs-aes-php.
may be this is the break after the "
from cryptojs-aes-php.
When i do just this, it works perfectly fine. So i guess you have some problems with your returned data from the ajax request, a line break or whatever.
var str = "{\"ct\":\"dxZkCuq\\\/H7YqQs3E5lrs9ZZ2c9M3O5TCL1Bdtnm\\\/1mkOyEVUOtNk8ZVNPnqp1Ca966dRjOV9k4FT+z7TpEmeYFZv2I1L+q6fWXIIQQIV\\\/m4RiA2V8MF4VEq7y5QBpteN\",\"iv\":\"5c0757952300fe019196d02a830c0af2\",\"s\":\"0c4a63c4dd46ac5b\"}";
console.log(JSON.parse(CryptoJS.AES.decrypt(str, "test123", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8)));
from cryptojs-aes-php.
Or you mabe doesn't have included cryptojs properly in your page, what does console.log(CryptoJS.AES.decrypt)
give you?
from cryptojs-aes-php.
I have included the following js files:
aes.js
aes-json-format.js
The result of console.log(CryptoJS.AES.decrypt) is:
function (b,k,d){return("string"==typeof k?c:a).decrypt(e,b,k,d)}
from cryptojs-aes-php.
so, what you get when you do just this for a test case on your page?
#8 (comment)
i don't think that this library or cryptojs have a problem here.
from cryptojs-aes-php.
Then I get the correct data:
[Object, Object]
0: Object
toon_amount: "3"
toon_clan: "testclan"
__proto__: Object
1: Object
toon_amount: "1"
toon_clan: "neuclan"
__proto__: Object
length: 2
__proto__: Array[0]
I think it's the break after the "
but I have no idea to fix it...
from cryptojs-aes-php.
Have you already tried just running the example files without modification?
If that work than i cannot help you in this specific task because it obviously as a bug in your code.
from cryptojs-aes-php.
Ok, now I tried some things... on php side at the return value with json_encode / decode and escape characters... nothing. Then I played with some things on the client side at the js function. A few more console.logs and I found a solution.
$scope.topClanToonsCount = JSON.parse(CryptoJS.AES.decrypt(JSON.parse(data), "test123", {format: CryptoJSAesJson}).toString(CryptoJS.enc.Utf8));
JSON.parse(data) was the solution.
brainfoolong thanks for your help and for pushing me to dig deeper in the code
from cryptojs-aes-php.
This is weird, It should not be required to double JSON.parse
the encrypted string.
Do you maybe have a second json_encode
in your code outside of cryptoJsAesEncrypt
from cryptojs-aes-php.
Yes, I do:
json_encode($app->handleAction($_REQUEST)
This issue can be closed.
from cryptojs-aes-php.
Ok, that's the bug :) You don't have to do this, the json_encode
inside the cryptoJsAesEncrypt
already does it. Closed.
from cryptojs-aes-php.
Related Issues (20)
- 提供一个py版本 HOT 1
- web-ftp-client HOT 1
- JS only / xhr instead of form name HOT 4
- What is the best way to contact you for one of project? HOT 1
- Unused variable declaration in your code HOT 4
- Ajax null result HOT 3
- unminified version of cryptojs-aes.min.js HOT 1
- no value returned.. HOT 3
- encrypt in JS and decrypt in PHP gives NULL HOT 4
- Not work HOT 4
- Simple Output Encrypted String HOT 3
- Not Working
- decrypt php return null or empty HOT 2
- toString(CryptoJS.enc.Utf8)) HOT 2
- Not Working in Safari browser. Is there any solutions. HOT 4
- Form Reset Not working after form submit using crypto js HOT 1
- PHP (Laravel) decrypt what CryptoJS encrypt HOT 1
- is there any way to encrypt image using cryptojs-aes-php? HOT 4
- Security vulnerability responsible disclosure HOT 2
- Atlantus update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cryptojs-aes-php.