PHP解密CryptoJS.AES.encrypt 不带IV
发布人:shili8
发布时间:2023-01-30 05:40
阅读次数:26
$ctOpenSSL = base64_decode("U2FsdGVkX1BUVUBB7Noz3lFOgEu9Z6qlFe6iGZyKU4ysOx2rdzEcw=");
$salt = substr($ctOpenSSL, 8, 8);
$ciphertext = substr($ctOpenSSL, 16);
// Derive key and IV
$keyIv = $this->EVP_BytesToKey($salt, "87R6W73IO8C43P32");
$key = substr($keyIv, 0, 32);
$iv = substr($keyIv, 32, 16);
// Decrypt
$decrypted = openssl_decrypt($ciphertext, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv);
public function EVP_BytesToKey($salt, $password) {
$bytes = '';
$last = '';
while(strlen($bytes) < 48) {
$last = hash('md5', $last . $password . $salt, true);
$bytes.= $last;
}
return $bytes;
}