Created attachment 36193 [details] Example of file produced. Using the code from https://poi.apache.org/encryption.html POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); // EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null); Encryptor enc = info.getEncryptor(); enc.confirmPassword("foobaa"); // Read in an existing OOXML file OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE); OutputStream os = enc.getDataStream(fs); opc.save(os); opc.close(); // Write out the encrypted version FileOutputStream fos = new FileOutputStream("..."); fs.writeFilesystem(fos); fos.close(); This works fine with 3.17 but doesn't work with 4.0.0. It just creates a 2k file that Microsoft Excel won't open.
Before I try to reproduce it, please add that "os.close()" before calling "fs.writeFilesystem()".
Yes adding os.close() as below resolves the issue. Thank you. POIFSFileSystem fs = new POIFSFileSystem( ); EncryptionInfo info = new EncryptionInfo( EncryptionMode.agile ); // EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile, // CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null); Encryptor enc = info.getEncryptor( ); enc.confirmPassword( "foobar" ); // Read in an existing OOXML file OPCPackage opc = OPCPackage.open( new File( "input.xlsx" ), PackageAccess.READ_WRITE ); OutputStream os = enc.getDataStream( fs ); opc.save( os ); opc.close( ); os.close( ); // Write out the encrypted version FileOutputStream fos = new FileOutputStream( "output.xlsx" ); fs.writeFilesystem( fos ); fos.close( );
fixed the documentation via r1843348