Created
August 18, 2020 13:23
-
-
Save Bo0oM/f7ceeae400f13d36ad895fe3466ef435 to your computer and use it in GitHub Desktop.
CryptoJS AES decrypt on PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* author: alexeyprudnikov | |
**/ | |
class JsAes { | |
public static function Decrypt($base64string, $secretkey) { | |
$base64string = str_replace('_', '+', $base64string); | |
$data = base64_decode($base64string); | |
$salt = substr($data, 8, 8); | |
$main = substr($data, 16); | |
$rounds = 3; | |
$sksalt = $secretkey . $salt; | |
$md5_hash = array(); | |
$md5_hash[0] = md5($sksalt, true); | |
$result = $md5_hash[0]; | |
for ($i = 1; $i < $rounds; $i++) { | |
$md5_hash[$i] = md5($md5_hash[$i - 1] . $sksalt, true); | |
$result .= $md5_hash[$i]; | |
} | |
$key = substr($result, 0, 32); | |
$iv = substr($result, 32, 16); | |
$decrypted = openssl_decrypt($main, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv); | |
return $decrypted; | |
} | |
} | |
echo JsAes::Decrypt("U2FsdGVkX18h3ECon7UNCJFga2JpEO7KANqqvul+C7A=", "myPassword"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment