aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/POIDocument.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/poi/POIDocument.java')
-rw-r--r--src/java/org/apache/poi/POIDocument.java10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java
index 519da97e3a..e2f613af64 100644
--- a/src/java/org/apache/poi/POIDocument.java
+++ b/src/java/org/apache/poi/POIDocument.java
@@ -271,7 +271,8 @@ public abstract class POIDocument implements Closeable {
*/
protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
final EncryptionInfo ei = getEncryptionInfo();
- final boolean encryptProps = (ei != null && ei.isDocPropsEncrypted());
+ Encryptor encGen = (ei == null) ? null : ei.getEncryptor();
+ final boolean encryptProps = (ei != null && ei.isDocPropsEncrypted() && encGen instanceof CryptoAPIEncryptor);
try (POIFSFileSystem tmpFS = new POIFSFileSystem()) {
final POIFSFileSystem fs = (encryptProps) ? tmpFS : outFS;
@@ -282,6 +283,8 @@ public abstract class POIDocument implements Closeable {
return;
}
+ // Only CryptoAPI encryption supports encrypted property sets
+
// create empty document summary
writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, newDocumentSummaryInformation(), outFS);
@@ -289,11 +292,6 @@ public abstract class POIDocument implements Closeable {
if (outFS.getRoot().hasEntry(SummaryInformation.DEFAULT_STREAM_NAME)) {
outFS.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
}
- Encryptor encGen = ei.getEncryptor();
- if (!(encGen instanceof CryptoAPIEncryptor)) {
- throw new EncryptedDocumentException(
- "Using " + ei.getEncryptionMode() + " encryption. Only CryptoAPI encryption supports encrypted property sets!");
- }
CryptoAPIEncryptor enc = (CryptoAPIEncryptor) encGen;
try {
enc.setSummaryEntries(outFS.getRoot(), getEncryptedPropertyStreamName(), fs);