0

I want to protect doc and docx files with password using java. I have tried using Apache POI. But it can't help me out.I am not getting any file at the location How would I do that? Any another way or API??

            POIFSFileSystem fs = new POIFSFileSystem();
            EncryptionInfo info = new EncryptionInfo(fs);
            File file=new File("D:/abc.doc");
            Encryptor enc = info.getEncryptor();
            enc.confirmPassword("xxxxx");

            OPCPackage opc = OPCPackage.open(file,PackageAccess.READ_WRITE);
            OutputStream os = enc.getDataStream(fs);
            opc.save(os);
            opc.close();

            FileOutputStream fos = new FileOutputStream("D:/abc12345.docs");
            fs.writeFilesystem(fos);
            fos.close(); 
Amar Malik
  • 477
  • 1
  • 4
  • 14

2 Answers2

0

See: http://www.quicklyjava.com/create-password-protected-excel-using-apache-poi/

Try this constructor for info object:

EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);

gargkshitiz
  • 2,130
  • 17
  • 19
-2

check this and try to adapt yourself http://www.quicklyjava.com/create-password-protected-excel-using-apache-poi/

A.s.e
  • 15
  • 2