Encrypt File With Aes-256 And Decrypt File To Its Original Format
Solution 1:
If you're working on files, then the only information that you might need to re-create that file after decryption is the file name and file extension.
One way to do this is to simply encrypt the file as-is without a special file format as "name.ext.anuj" when the file that you encrypted was "name.ext". It contains everything to re-create the original file.
The problem with this is that the filename is shown. Sometimes meta-data such as a filename is all an attacker needs. Think about when your spouse finds a file "divorce.odf.anuj".
In those cases, you can define a new file format. You can for example take the filename, write it into a stream (maybe prepend it with the filename length which DataOutputStream
provides) and write the actual file contents after that as byte[]
. Now, you can encrypt the whole thing. When you decrypt it, simply read the filename from the front and write to this file the remaining decrypted bytes.
Post a Comment for "Encrypt File With Aes-256 And Decrypt File To Its Original Format"