Comments (4)
Hi, your suggested code is not from this project.
from cryptojs-aes-php.
No?
Here is the original code:
<?php
/**
* Helper library for CryptoJS AES encryption/decryption
* Allow you to use AES encryption on client side and server side vice versa
*
* @author BrainFooLong (bfldev.com)
* @link https://github.com/brainfoolong/cryptojs-aes-php
*/
/**
* Decrypt data from a CryptoJS json encoding string
*
* @param mixed $passphrase
* @param mixed $decrypted
* @return mixed
*/
function cryptoJsAesDecrypt($decrypted, $passphrase)
{
list ($decstr, $comb) = explode("*", $decrypted);
$decstrf = $decstr;
$combnorm = substr($comb, 0, 48);
$cnarr = str_split($combnorm, 4);
$s = $cnarr[0] . $cnarr[2] . $cnarr[4] . $cnarr[6];
$ivr = $cnarr[1] . $cnarr[3] . $cnarr[5] . $cnarr[7] . $cnarr[8] . $cnarr[9] . $cnarr[10] . $cnarr[11];
try
{
$salt = hex2bin($s);
$iv = hex2bin($ivr);
}
catch (Exception $e)
{
return $combnorm;
}
$ct = base64_decode($decstrf);
$concatedPassphrase = $passphrase . $salt;
$md5 = array();
$md5[0] = md5($concatedPassphrase, true);
$result = $md5[0];
for ($i = 1; $i < 3; $i ++)
{
$md5[$i] = md5($md5[$i - 1] . $concatedPassphrase, true);
$result .= $md5[$i];
}
$key = substr($result, 0, 32);
$data = openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
if ($data == FALSE)
{
return "passphrase:" . $passphrase;
}
else
{
return json_decode($data, true);
}
//return json_decode($data, true);
}
/**
* Encrypt value to a cryptojs compatiable json encoding string
*
* @param mixed $passphrase
* @param mixed $value
* @return string
*/
function cryptoJsAesEncrypt($passphrase, $value, $map_id)
{
$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);
$s = str_split(bin2hex($salt), 4);
$ivr = str_split(bin2hex($iv), 4);
$comb = $s[0] . $ivr[0] . $s[1] . $ivr[1] . $s[2] . $ivr[2] . $s[3] . $ivr[3] . $ivr[4] . $ivr[5] . $ivr[6] . $ivr[7];
$map_iid = $map_id * hexdec($s[0]);
$encrypted_data = openssl_encrypt(json_encode($value), 'aes-256-cbc', $key, true, $iv);
$data = array(
"ct" => base64_encode($encrypted_data) . "*" . $comb . $map_iid,
"s" => $s,
"ivr" => $ivr
);
return base64_encode($encrypted_data) . "*" . $comb . $map_iid;
}
But i don't know where the programmer has found it...? (I just saw that Eclipse warning while code refactoring)
So the code above is not an older version from your aes library?
from cryptojs-aes-php.
No, this is a modified version. You should not use this. It contains some weird things, maybe some custom salts and initialization vectors. Better download the original version from here.
from cryptojs-aes-php.
Thank you very much!!
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
- 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.