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:00:38 UTC

[Bug 62967] New: Stream Closed For EncryptionInfo

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

            Bug ID: 62967
           Summary: Stream Closed For EncryptionInfo
           Product: POI
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: POIFS
          Assignee: dev@poi.apache.org
          Reporter: yanleichang@vip.163.com
  Target Milestone: ---

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();
```

-- 
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


[Bug 62967] Stream Closed For EncryptionInfo

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62967

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|NEW                         |RESOLVED

--- Comment #3 from Robot <ya...@vip.163.com> ---
I got it.

-- 
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


[Bug 62967] Stream Closed For EncryptionInfo

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62967

--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
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.

-- 
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


[Bug 62967] Stream Closed For EncryptionInfo

Posted by bu...@apache.org.
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