Update: 2026-07-22 18:23:10

This commit is contained in:
Hamza-Ayed
2026-07-22 18:23:10 +03:00
parent f76623a25e
commit 55fbe22f8e
+16 -2
View File
@@ -59,12 +59,26 @@ class EncryptionHelper
return $plain !== false ? $plain : false;
}
// وإلا استخدم CBC القديم
// وإلا استخدم CBC القديم (دعم IV العشوائي المسبوق و IV الثابت)
$decoded = base64_decode($cipherText, true);
if ($decoded === false) return false;
// محاولة أولى: IV عشوائي مسبوق (أول 16 بايت)
if (strlen($decoded) >= 32) {
$iv = substr($decoded, 0, 16);
$payload = substr($decoded, 16);
$decrypted = openssl_decrypt($payload, self::ALGO_CBC, $this->key, OPENSSL_RAW_DATA, $iv);
if ($decrypted !== false && strlen($decrypted) > 0) {
$pad = ord($decrypted[strlen($decrypted) - 1]);
if ($pad >= 1 && $pad <= 16) {
return substr($decrypted, 0, -$pad);
}
}
}
// محاولة ثانية: IV ثابت
$decrypted = openssl_decrypt($decoded, self::ALGO_CBC, $this->key, OPENSSL_RAW_DATA, $this->cbcIv);
if ($decrypted === false) return false;
if ($decrypted === false || strlen($decrypted) === 0) return false;
$pad = ord($decrypted[strlen($decrypted) - 1]);
if ($pad < 1 || $pad > 16) return false;