在 Compact Framework 中安全擦除文件

发布于 2024-09-10 05:31:13 字数 272 浏览 1 评论 0原文

给定字符串的路径,我想擦除文件的内容。我认为(可能不正确)的自然方式是打开文件的 FileStream 并向其中写入乱码(可能从 RNGCryptoServiceProvider 获取的随机数据)。然后也许这样做几次,然后删除该文件。

我的问题是,虽然这在逻辑上看起来可能是正确的,但我在另一个博客上读到 Windows 实际上可能选择将文件写入硬盘中的不同位置。

Windows Mobile 也是这样吗?这实际上会成为问题吗?这种写入硬盘中不同位置的操作是否也适用于基于闪存(SD 等)的卡?

Given the path of a string i want to wipe out the contents of a file. The natural way I thought (which maybe incorrect) was to open a FileStream to the file and write gibberish (random data perhaps taken from a RNGCryptoServiceProvider) to it. And then perhaps do this several times and then delete the file.

My problem is that while this may look logically correct, i read up on another blog that Windows might actually choose to write the file to a different place in the hard disk.

Is that the case in Windows Mobile? Will this actually be a problem? Does this writing to a different location in the hard disk apply to even flash based (SD etc) cards ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2024-09-17 05:31:13

我个人没有这样做过,但您可能需要使用低级闪存驱动程序 IOCTL 才能正确执行此操作。

http://msdn.microsoft.com/en-us/library/aa927166.aspx

我认为 IOCTL_FMD_RAW_WRITE_BLOCKS 看起来特别有用。

-PaulH


另一种可行的方法是正常擦除文件,然后使用碎片整理 API 擦除闪存上的所有可用空间。由于您要擦除所有内容,因此无需确切知道文件在磁盘上的位置。但是,这会更快地磨损您的闪存驱动器。此博客文章详细介绍了 C# 方法: http:// /blogs.msdn.com/b/jeffrey_wall/archive/2004/09/13/229137.aspx

I've not personally done this, but you will probably need to use the low-level FLASH driver IOCTLs to do this correctly.

http://msdn.microsoft.com/en-us/library/aa927166.aspx

I think IOCTL_FMD_RAW_WRITE_BLOCKS looks particularly useful.

-PaulH


Another possibility that may work would be to erase the file normally, then use the defragment APIs to wipe ALL of the freespace on your flash. Since you're wiping everything, it won't be necessary to know exactly where on the disk your file was. But, this will wear out your flash drive more quickly. The C# method is detailed in this blog post: http://blogs.msdn.com/b/jeffrey_wall/archive/2004/09/13/229137.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文