简体   繁体   中英

Secure delete with PHP 5.3.x

Does someone knows an good PHP Solution to delete or better wipe an file from an linux system?

Scenario: File is encrypted and saved, when a download is requested the file is copyed to an temporary folder and decrypted. This is already working.

But how to remove the file from the temporary location after sending in to the user?

In my mind i have the following options:

  • Open the File via "fopen" and write 0,1 into it (think very slow)
  • Save file to Memcache instead of harddisk (could be a problem with my hoster)
  • Use somd 3rd pary tool on commandline or as cronjob (could be a problem to install)

Goal: Delete the file from hard disk, without the possibility to recover (wipe/overwrite)

通过exec / system / passthru调用“ shred

Arguably the best is to never save the file in its decrypted state in the first place.

Rather, use stream filters to decrypt it on-the-fly and send it directly to the end-user.

Update

Your option 1 is actually not too bad if you consider this code:

$filename = 'path/to/file';
$size = filesize($filename);

$src = fopen('/dev/zero', 'rb');
$dest = fopen('/path/to/file', 'wb');

stream_copy_to_stream($src, $dest, $size);

fclose($src);
fclose($dest);

You could choose /dev/urandom as well, but that will be slow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM