Exo Naut
Exo Naut

Reputation: 31

Java JCE Encrypt Folders?

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.

Upvotes: 3

Views: 3119

Answers (1)

Freedom_Ben
Freedom_Ben

Reputation: 11933

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.

Upvotes: 4

Related Questions