C中的安全文件删除 [英] Secure File Delete in C

查看:120
本文介绍了C中的安全文件删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中删除安全文件



我需要安全地删除C中的一个文件,这里是我做的:


  1. 使用 fopen 来获取文件的句柄
  2. 使用 lseek / ftell

  3. 取决于当前时间或文件大小, / li>
  4. 从每个循环写入256个字节的循环中写入(大小)字节到文件中
  5. fflush / fclose 文件句柄
  6. 重新打开文件并重新执行步骤3-6 10到15次
  7. >
  8. 重新命名文件,然后将其删除

是这样做的吗?因为我在橡皮擦中读到了Gutmann 25 passes这个名字,所以我猜25是文件被覆盖的次数,Gutmann是随机化算法吗?

解决方案

在没有操作系统的协作的情况下,你不能安全地做到这一点 - 甚至不是这样。



当你打开文件和写入它不能保证操作系统将把新的文件放在旧的一个旋转锈的位。即使这样做,你也不知道新的写入是否会像以前一样使用相同的簇链。即使这样,您也不能确定驱动器是否因为某些故障而没有映射出磁盘块 - 在标记的块上留下统治世界的计划坏的,但仍然可读。



ps - 25x覆盖不再是必需的,在老式低密度MFM驱动器上需要头部跟踪较差。在现代GMR驱动器覆盖一次是很多。


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?

解决方案

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.

这篇关于C中的安全文件删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆