<?php
use Cryptography\Ciphers\Cipher;
use Cryptography\Ciphers\Algorithms;
use Cryptography\Ciphers\Modes;
use Cryptography\Backends\DefaultBackend;
function decrypt_file($encrypted_file, $key, $iv) {
$file = fopen($encrypted_file, 'rb');
$cipher = new Cipher(new Algorithms\AES($key), new Modes\CFB8($iv), new DefaultBackend());
$decryptor = $cipher->decryptor();
$decrypted_text = $decryptor->update($ciphertext) . $decryptor->finalize();
$decrypted_file = fopen(substr($encrypted_file, 0, -4) . '_decrypted.txt', 'wb'); fwrite($decrypted_file, $decrypted_text);
// Print the decrypted content
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$key = $_POST['key']; // استلام المفتاح كمدخل من المستخدم
$iv = hex2bin($_POST['iv']); // استلام iv كسلسلة سداسية وتحويلها إلى ثنائية
$file_path = "Data.txt.enc";
decrypt_file($file_path, $key,$iv);
}
?>
PD9waHAKCnVzZSBDcnlwdG9ncmFwaHlcQ2lwaGVyc1xDaXBoZXI7CnVzZSBDcnlwdG9ncmFwaHlcQ2lwaGVyc1xBbGdvcml0aG1zOwp1c2UgQ3J5cHRvZ3JhcGh5XENpcGhlcnNcTW9kZXM7CnVzZSBDcnlwdG9ncmFwaHlcQmFja2VuZHNcRGVmYXVsdEJhY2tlbmQ7CgpmdW5jdGlvbiBkZWNyeXB0X2ZpbGUoJGVuY3J5cHRlZF9maWxlLCAka2V5LCAkaXYpIHsKICAgICRmaWxlID0gZm9wZW4oJGVuY3J5cHRlZF9maWxlLCAncmInKTsKICAgICRjaXBoZXJ0ZXh0ID0gZnJlYWQoJGZpbGUsIGZpbGVzaXplKCRlbmNyeXB0ZWRfZmlsZSkpOwogICAgZmNsb3NlKCRmaWxlKTsKCiAgICAkY2lwaGVyID0gbmV3IENpcGhlcihuZXcgQWxnb3JpdGhtc1xBRVMoJGtleSksIG5ldyBNb2Rlc1xDRkI4KCRpdiksIG5ldyBEZWZhdWx0QmFja2VuZCgpKTsKICAgICRkZWNyeXB0b3IgPSAkY2lwaGVy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