Bug 62811 - POI Encryption didn't work with 4.0.0 but did work with 3.17
Summary: POI Encryption didn't work with 4.0.0 but did work with 3.17
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 4.0.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-09 13:54 UTC by John Kleiser
Modified: 2018-10-09 21:41 UTC (History)
1 user (show)



Attachments
Example of file produced. (1.50 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2018-10-09 13:54 UTC, John Kleiser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Kleiser 2018-10-09 13:54:46 UTC
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.
Comment 1 Andreas Beeker 2018-10-09 18:18:07 UTC
Before I try to reproduce it, please add that "os.close()" before calling "fs.writeFilesystem()".
Comment 2 John Kleiser 2018-10-09 19:33:40 UTC
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( );
Comment 3 Andreas Beeker 2018-10-09 21:41:50 UTC
fixed the documentation via r1843348