You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2018/11/30 09:07:48 UTC

[Bug 62967] Stream Closed For EncryptionInfo

https://bz.apache.org/bugzilla/show_bug.cgi?id=62967

Robot <ya...@vip.163.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Robot <ya...@vip.163.com> ---
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();
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org