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();
See: http://www.quicklyjava.com/create-password-protected-excel-using-apache-poi/
Try this constructor for info object:
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.