Update: 2026-06-11 18:22:57
This commit is contained in:
97
walletintaleq.intaleq.xyz/v2/main/en.php
Executable file
97
walletintaleq.intaleq.xyz/v2/main/en.php
Executable file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '../../../vendor/autoload.php';
|
||||
// Load environment variables from .env file
|
||||
$env_file = dirname(__DIR__) . '/dd/.env';
|
||||
|
||||
if (file_exists($env_file)) {
|
||||
$lines = file($env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
// Remove leading/trailing whitespace
|
||||
$line = trim($line);
|
||||
|
||||
// Skip comments (lines starting with #) and empty lines
|
||||
if (empty($line) || strpos($line, '#') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split the line into key and value
|
||||
$parts = explode('=', $line, 2); // Limit to 2 parts
|
||||
|
||||
// Check if we have both key and value
|
||||
if (count($parts) === 2) {
|
||||
list($key, $value) = $parts;
|
||||
//remove any quotes around the value.
|
||||
$value = trim($value, "'\"");
|
||||
// Set the environment variable
|
||||
putenv("$key=$value");
|
||||
} else {
|
||||
// Log a warning if the line is invalid. CRITICAL for debugging!
|
||||
error_log("Invalid line in .env file: " . $line);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ✅ كلاس التشفير المتطابق مع Flutter
|
||||
class EncryptionHelper {
|
||||
private $key;
|
||||
private $iv;
|
||||
|
||||
public function __construct($key, $iv) {
|
||||
if (strlen($key) !== 32) {
|
||||
throw new Exception("❌ المفتاح (Key) لازم يكون 32 بايت.");
|
||||
}
|
||||
if (strlen($iv) !== 16) {
|
||||
throw new Exception("❌ الـ IV لازم يكون 16 بايت.");
|
||||
}
|
||||
|
||||
$this->key = $key;
|
||||
$this->iv = $iv;
|
||||
}
|
||||
|
||||
private function addPadding($data, $blockSize = 16) {
|
||||
$pad = $blockSize - (strlen($data) % $blockSize);
|
||||
return $data . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
private function removePadding($data) {
|
||||
$pad = ord($data[strlen($data) - 1]);
|
||||
return substr($data, 0, -$pad);
|
||||
}
|
||||
|
||||
public function encryptData($plainText) {
|
||||
$plainText = mb_convert_encoding($plainText, 'UTF-8');
|
||||
$paddedText = $this->addPadding($plainText);
|
||||
$encrypted = openssl_encrypt($paddedText, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
|
||||
public function decryptData($encryptedText) {
|
||||
$decoded = base64_decode($encryptedText);
|
||||
$decrypted = openssl_decrypt($decoded, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
|
||||
return $this->removePadding($decrypted);
|
||||
}
|
||||
}
|
||||
|
||||
$key = getenv('keyOfApp');
|
||||
$iv = getenv('initializationVector');
|
||||
|
||||
echo "Key Length: " . strlen($key) . PHP_EOL;
|
||||
echo "IV Length: " . strlen($iv) . PHP_EOL;
|
||||
|
||||
$encryptionHelper = new EncryptionHelper($key, $iv);
|
||||
$storedHash = '$2y$10$cM9AJ.EJyX1zj8zReTw8CO.Rcr6XW.8njmHeezEqsv4OlEWyHHA4S';
|
||||
$userProvidedPassword = 'unknown'; // This would come from the user input
|
||||
|
||||
if (password_verify($userProvidedPassword, $storedHash)) {
|
||||
echo "🔹 password_verify: Password is correct." . PHP_EOL;
|
||||
} else {
|
||||
echo "🔹 password_verify: Incorrect password." . PHP_EOL;
|
||||
}
|
||||
|
||||
$plainText = "unknown";
|
||||
$encryptedText = $encryptionHelper->encryptData($plainText);
|
||||
$decryptedText = $encryptionHelper->decryptData($encryptedText);
|
||||
|
||||
echo "🔹 Original Text: $plainText" . PHP_EOL;
|
||||
echo "🔹 Encrypted Text: $encryptedText" . PHP_EOL;
|
||||
echo "🔹 Decrypted Text: $decryptedText" . PHP_EOL;
|
||||
Reference in New Issue
Block a user