Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure File Delete in C

Tags:

c

file-io

Secure File Deleting in C

I need to securely delete a file in C, here is what I do:

  1. use fopen to get a handle of the file
  2. calculate the size using lseek/ftell
  3. get random seed depending on current time/or file size
  4. write (size) bytes to the file from a loop with 256 bytes written each iteration
  5. fflush/fclose the file handle
  6. reopen the file and re-do steps 3-6 for 10~15 times
  7. rename the file then delete it

Is that how it's done? Because I read the name "Gutmann 25 passes" in Eraser, so I guess 25 is the number of times the file is overwritten and 'Gutmann' is the Randomization Algorithm?

like image 883
killercode Avatar asked Oct 13 '11 16:10

killercode


People also ask

How do I secure delete files?

If you're a Windows 10 user, you can securely delete files using third-party apps like Eraser, file shredder, or Freeraser. Using either of these methods, you can securely delete individual files and folders depending on your preference.

What is secure file deletion?

A secure delete application or process prevents the recovery of deleted files by overwriting the file data with meaningless data. Securely erasing data with this procedure is considered a best practice for eliminating sensitive data, and it is a critical task to perform if you sell or give away your computer.

Is rm Secure delete?

Every time you delete a file from your Linux system using the shift + delete or rm command, it doesn't actually permanently and securely delete the file from the hard disk.

How do you permanently erase data so that it Cannot be recovered?

Go to Settings > Security > Advanced and tap Encryption & credentials. Select Encrypt phone if the option isn't already enabled. Next, go to Settings > System > Advanced and tap Reset options. Select Erase all data (factory reset), and press Delete all data.


1 Answers

You can't do this securely without the cooperation of the operating system - and often not even then.

When you open a file and write to it there is no guarantee that the OS is going to put the new file on the same bit of spinning rust as the old one. Even if it does you don't know if the new write will use the same chain of clusters as it did before.

Even then you aren't sure that the drive hasn't mapped out the disk block because of some fault - leaving your plans for world domination on a block that is marked bad but is still readable.

ps - the 25x overwrite is no longer necessary, it was needed on old low density MFM drives with poor head tracking. On modern GMR drives overwriting once is plenty.

like image 56
Martin Beckett Avatar answered Sep 24 '22 18:09

Martin Beckett