fork download
  1. import os;
  2. use \Cryptography\Ciphers\Cipher;
  3. use \Cryptography\Ciphers\Algorithms;
  4. use \Cryptography\Ciphers\Modes;
  5. use \Cryptography\Backends\DefaultBackend;
  6.  
  7. function decrypt_file($encrypted_file, $key, $iv) {
  8. $file = fopen($encrypted_file, 'rb');
  9. $ciphertext = fread($file, filesize($encrypted_file));
  10. fclose($file);
  11.  
  12. $cipher = new Cipher(new Algorithms\AES($key), new Modes\CFB8($iv), new DefaultBackend());
  13. $decryptor = $cipher->decryptor();
  14. $decrypted_text = $decryptor->update($ciphertext) . $decryptor->finalize();
  15.  
  16. $decrypted_file = fopen(substr($encrypted_file, 0, -4) . '_decrypted.txt', 'wb');
  17. fwrite($decrypted_file, $decrypted_text);
  18. fclose($decrypted_file);
  19.  
  20. // Print the decrypted content
  21. echo utf8_decode($decrypted_text);
  22. }
  23.  
  24. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  25. $key = b'*\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00'; // Should be 16, 24, or 32 bytes long
  26. $iv = b'\xdam-4BW$\x89\x8b\x19\x9e0.G\x89\xcd'; // Should be 16 bytes long
  27. $file_path = "Data.txt.enc";
  28. decrypt_file($file_path, $key, $iv);
  29. }
Success #stdin #stdout 0.02s 25952KB
stdin
Standard input is empty
stdout
import os;
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');
    $ciphertext = fread($file, filesize($encrypted_file));
    fclose($file);

    $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);
    fclose($decrypted_file);

    // Print the decrypted content
    echo utf8_decode($decrypted_text);
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $key = b'*\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00';  // Should be 16, 24, or 32 bytes long
    $iv = b'\xdam-4BW$\x89\x8b\x19\x9e0.G\x89\xcd'; // Should be 16 bytes long
    $file_path = "Data.txt.enc";
    decrypt_file($file_path, $key, $iv);
}