有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

文件系统是否可以用java覆盖文件,使其无法恢复?

我正在写一个加密程序来加密文件

我希望加密的内容将替换原始内容,使其无法通过恢复程序恢复(即,使用与原始内容相同的内存地址)

假设加密内容的大小与原始内容相同

我猜File.renameTo()不会起作用,因为它是独立于平台的,所以有点不可预测

请原谅我没有发布我的完整代码(duh!){cdi}使用


共 (1) 个答案

  1. # 1 楼答案

    在某些情况下(在某些操作系统上,在某些文件系统上,使用一些装载选项)RandomAccessFile将允许您执行您想要执行的操作。还要考虑如何将敏感数据保留在Java堆之外。。。例如,避免使用String作为从未加密文件构造的对象的一部分,然后将其写入加密文件。然而,在其他情况下,你的建议是根本不可能的。如GNU的手册页所述

    CAUTION: Note that shred relies on a very important assumption: that the file system overwrites data in place. This is the traditional way to do things, but many modern file system designs do not satisfy this assumption. The following are examples of file systems on which shred is not effective, or is not guaranteed to be effective in all file system modes:

    • log-structured or journaled file systems, such as those supplied with AIX and Solaris (and JFS, ReiserFS, XFS, Ext3, etc.)
    • file systems that write redundant data and carry on even if some writes fail, such as RAID-based file systems
    • file systems that make snapshots, such as Network Appliance’s NFS server
    • file systems that cache in temporary locations, such as NFS version 3 clients
    • compressed file systems