Is it possible to encrypt entire folders with Java's JCE library. The folders will contain other folders/files if that is a problem. For those who don't know what JCE is, it stands for Java Cryptography Extension and it is used for encryption in Java.
- You could ZIP the folders and then encrypt that data?Duncan Jones– Duncan Jones2013-05-21 20:32:10 +00:00Commented May 21, 2013 at 20:32
- But is it possible to just encrypt the folder? If I have to encrypt a zip its another step in the decrypting process to access the zip.Exo Naut– Exo Naut2013-05-21 21:39:33 +00:00Commented May 21, 2013 at 21:39
1 Answer
No. You can't encrypt entire folders with only Java's JCE library. It's not hard to zip it first though using a stream wrapper like ZipInputStream and ZipOutputStream. Since you don't care about file size reduction, you could also use jtar. That will make it easy to tar up the folder after which it can be encrypted with JCE like any other file.
I would make a class called something like public class FolderEncrypter with methods public byte[] encryptFolder(File folder) and public File decryptFolder(public byte[]). Then it is easy to reuse throughout your code whenever you need it.
4 Comments
encryptFolder should return a byte[] and decryptFolder should accept a byte[] as a parameter.