2

I'm working on a project to Encrypt files using AES encryption with a key generated from SHA-256 from a keyword.

My idea to claim this was to

first : read all bytes from a file

second : encrypt bytes

third : write encrypted bytes on same file

I had some reasons to write encrypted bytes on same file. one was to prevent data recovery. as far as I know, the standard way to do this is to write encrypted data on new file and then remove old file. but I know old file can still be recovered and thats the problem "If old non-encrypted data can be recovered, what is the use of encryption?"

In my experience, I could always reach last version of files when I recovered them, not the history of file changes.

for example I have text file with "This text" in it, and I change it to "This text is changed". When I recovered my files, I could just see a text file containing "This text is changed". (Can old version still be recovered ?!) . so this became my logic to rewrite encrypted data on same file which I'm sure its too risky and buggy !! but would this fulfill my wish ?

I've posted my codes and logics in stackoverflow here . Then answers made me search more about data recovery. I also could read this article about data recovery. If I'm not wrong, file systems on HHDs will just remove a pointer to the file not the file itself so it can be recovered. Thats where I thought I have to rewrite on same file but answers in stackOverFlow told me its useless.

So can you give me details how I can at least HELP preventing old and non-encrypted file from being recovered ?

Also same article wrote something about SSD hard drive, which I think might be my answer (I read if I rewrite data on SSD hard drives it might be completely unrecoverable). How would I do this ?

Thanks.


Any information about how can I overwrite the left space (in case I change my output and write encrypted files to elsewhere) and preventing data recovery could be helpful.

FYI: I code with JAVA... examples can help me too

  • 1
    I think you have it backwards - thanks to wear leveling, even if you rewrite the "same" blocks on an SSD, the controller may write the data someplace completely different, leaving the old data intact (which may or may not be recoverable using low level tools). Even a magnetic hard drive might remap sectors leaving your unencrypted data subject to recovery, even if you overwrite all free space. The best way to prevent data from being recovered is to not write it in plain text in the first place. – Johnny Jan 12 '16 at 6:54
  • @Johnny Thanks for your helpful information. I also liked your idea about not to write it in plain text in the first place, but thats not gonna happen easily, considering we are encrypting files that already exist in HDD or anywhere, so after all they are reachable. And I wonder where could Decryptor put its output ?! anywhere we save decrypted output, it is recoverable too, right ? any ideas about how to solve it ?! – Sep GH Jan 12 '16 at 7:19
  • Johnny's comment is correct for SSDs. It may be messy but there could be some old data still around like that. Is full disk encryption not an option? Some SSDs also have always-on encryption built in. I guess we could use some more requirements. You want to prevent data recovery... Does that include someone running data recovery software on a running and logged in system? Or just on the removed drive? Do you need to encrypt only individual files in one area and not the rest of the data? – Datarecovery.com MK Jan 13 '16 at 15:46
  • Oh I'll also say that you may not have enough control with Java to know where the original file was located and to be able to modify that area. This is because the OS handles operation of the storage and Java has to go through that. The OS may not have any functionality to provide that information. – Datarecovery.com MK Jan 13 '16 at 15:52
  • @Datarecovery.comMK I'm thinking for solutions to prevent it when even someone is running a data recovery software on a logged in and running system. (although information about removed drive might help too). and yes , I want to encrypt only individual files not all data/partition/hard. This is what my program is focusing on. so this should work on both encrypted or non-encrypted hard drives. – Sep GH Jan 13 '16 at 15:53
2

Most encryption software like bitlocker or Truecrypt will offer you to overwrite the space that's left with random bytes, resulting in the file being deleted.

Another option is using a fileshredder. Look for any shredder using the Gutmann method

  • Thanks . Do you know any file shredder which works with command line for both windows and linux ? Also a Java library for shredding can be helpful so that I can use it in my own program. – Sep GH Jan 13 '16 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.