Bug 62967 - Stream Closed For EncryptionInfo
Summary: Stream Closed For EncryptionInfo
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: POIFS (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-30 09:00 UTC by Robot
Modified: 2018-11-30 10:17 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robot 2018-11-30 09:00:38 UTC
When I use the following code(from the official document)

```java
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 and write to encrypted output stream
// don't forget to close the output stream otherwise the padding bytes aren't added
try (OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE);
    OutputStream os = enc.getDataStream(fs)) {
    opc.save(os);
}

// Write out the encrypted version
FileOutputStream fos = new FileOutputStream("...");
fs.writeFilesystem(fos);
fos.close();
``` 

The following error occurred

----- 其他异常 : class java.io.IOException
java.io.IOException: Stream Closed
	at java.io.FileOutputStream.writeBytes(FileOutputStream.java) ~[na:1.8.0_191-1-ojdkbuild]
	at java.io.FileOutputStream.write(FileOutputStream.java:326) ~[na:1.8.0_191-1-ojdkbuild]
	at org.apache.poi.poifs.crypt.agile.AgileEncryptor$ChunkedCipherOutputStream.writeChunk(AgileEncryptor.java:330) ~[poi-ooxml-3.10-FINAL.jar:3.10-FINAL]
	at org.apache.poi.poifs.crypt.agile.AgileEncryptor$ChunkedCipherOutputStream.close(AgileEncryptor.java:337) ~[poi-ooxml-3.10-FINAL.jar:3.10-FINAL]


Everything is normal after modification

```java
OPCPackage opc = OPCPackage.open(new File(filePath), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
```
Comment 1 Robot 2018-11-30 09:07:48 UTC
When I use the following code(from the official document) poi verion 3.10.0
```java
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(fs, 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 and write to encrypted output stream
// don't forget to close the output stream otherwise the padding bytes aren't added
try (OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE);
    OutputStream os = enc.getDataStream(fs)) {
    opc.save(os);
}

// Write out the encrypted version
FileOutputStream fos = new FileOutputStream("...");
fs.writeFilesystem(fos);
fos.close();
``` 

The following error occurred

----- 其他异常 : class java.io.IOException
java.io.IOException: Stream Closed
	at java.io.FileOutputStream.writeBytes(FileOutputStream.java) ~[na:1.8.0_191-1-ojdkbuild]
	at java.io.FileOutputStream.write(FileOutputStream.java:326) ~[na:1.8.0_191-1-ojdkbuild]
	at org.apache.poi.poifs.crypt.agile.AgileEncryptor$ChunkedCipherOutputStream.writeChunk(AgileEncryptor.java:330) ~[poi-ooxml-3.10-FINAL.jar:3.10-FINAL]
	at org.apache.poi.poifs.crypt.agile.AgileEncryptor$ChunkedCipherOutputStream.close(AgileEncryptor.java:337) ~[poi-ooxml-3.10-FINAL.jar:3.10-FINAL]


Everything is normal after modification

```java
OPCPackage opc = OPCPackage.open(new File(filePath), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
```
Comment 2 PJ Fanning 2018-11-30 09:55:53 UTC
The web site only has documentation for the current version of poi (4.0.0 with 4.0.1 coming out soon).
POI 3.10 is ancient.
Comment 3 Robot 2018-11-30 10:17:35 UTC
I got it.