Task: damage the file to make it impossible to read it. (And successful recovery if it is deleted programmatically on the same machine (in the way available to the average Google search user))

Hiding the fact of overwriting a file does not interest. The volume of files and their number is any (can be calculated along the way)

Type of storage - any (can be calculated along the way)

View any files ...

What algorithm will consider speed and efficiency?

The first thing that came to mind was to open the file in a stream, and walk with a certain step, "poking" zero bytes. What can be improved?

C # code:

private void FileDamage(Stream stream) { using (stream) { const int upper = 1000; var step = stream.Length / upper; if (step == 0) step = 1; for (long l = 0; l < upper; l++) { stream.Seek(step, SeekOrigin.Current); stream.WriteByte(0); } } } 

PS I do not want to completely overwrite the file (or even repeatedly). The question is what is sufficient in this case.

    2 answers 2

    It depends on what file (the data is inside the file) and what “impossibility of recovery” means to you and depends strongly on the size.

    • For starters, you can read https://ru.wikipedia.org/wiki/Data_Deletion - these are data destruction standards
    • In principle, the best way is to simply write the entire file at a low level with the "01010101" bit pattern and then the "10101010" second time — then no one will ever recover your data. Even from the hard disk.
    • If this is a running binary, you can try to "thin out" it with "zeros" in increments of less than 50
    • If it is a text or a picture, then all bytes must be deleted, or it can be quite well recovered logically or algorithmically.
    • The file size is indirectly dependent on its type. And the type in theory can be any (you can of course make several algorithms and select on the fly) - Opossum
    • @Opossum Then it’s better to just rub the entire file 1 time with zeros or patterns that I wrote. Then your file will not be restored. It is worth writing several algorithms only if you are 100% sure that you can always determine with 100% certainty what kind of file you are overwriting. - Axenow
    • @Opossum Accept the answer if it seems correct to you. Thank you - Axenow
    • one
      @Opossum If you do not destroy keyframes and data in the file, then you can restore it in a few hours. The fact is that in the video there are reference frames that show the whole picture and the subsequent frames show only the difference. If you have even a few key frames - you can recover very, very much. In principle - it is a long time, I agree. - Axenow
    • 3
      Does it make sense to wipe it on the SSD? In the same place, in essence, the erase template will be written to the new free space, and the old connection will simply be lost until TRIM is executed. - Gennady P

    I remember that in the legendary Norton Utilities package there were Wipe utilities that wiped data with a multiple pass, recording various data (to the delight of the paranoid).

    I also recall the Watergate scandal, when a tape recording was accidentally erased by a secretary. And how then tried to restore this record.

    From this we can conclude that even an erased entry can (try) to recover. Moreover, besides magnetic media, there are optical and flash ...

    In general, everything is not so simple.


    If I had written a utility for mashing data, I would have done at least two passes: once all the bits are written with zeros, another time with single digits. This, in my amateurish view, will give a greater degree of confidence that there will be no pickup of magnetic fields along the edges of the track (although on a tape, even on a disk).

    This, as it seems to me, is true for magnetic drives, for optical, and for flash memory (except SSD).

    SSD is a special conversation. To reduce cell wear, the controller can transfer data to less-used cells. As a result, as I understand it, the same data can be physically duplicated on the drive. The old copy will be erased when writing new data, but until then it is there. And when we seemingly overwrite our file, the data is still present on the drive in the previous area. And they can be extracted, IMHO.

    I suppose, only complete mashing of the entire volume of the drive will help here. Correct, if I am mistaken.

    • So, let's clarify the problem. Interested in the avoidance of software recovery, without removing the disk and picking in magnetic fields in search of residues. - Opossum
    • one
      @Opossum Then write down any information on top. On the HDD, this will overwrite the information without the possibility of recovery, and on the SSD, the old information will eventually clear TRIM (which can be forced to run, if I'm not mistaken). - Gennady P