aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/poifs
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2017-06-06 22:21:11 +0000
committerAndreas Beeker <kiwiwings@apache.org>2017-06-06 22:21:11 +0000
commit1bcde5f6d490a6782a8d12ae571fc32ace45056d (patch)
tree8d05c52441ab318868733fced6ae0bc7ffbed38e /src/java/org/apache/poi/poifs
parent8909c066be7b3e341f0ef3d8302833d1e68bb5e9 (diff)
downloadpoi-1bcde5f6d490a6782a8d12ae571fc32ace45056d.tar.gz
poi-1bcde5f6d490a6782a8d12ae571fc32ace45056d.zip
#61162 - En-/decryption support for HWPF
Decryption for Binary RC4 and CryptoAPI (... XOR is missing) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797837 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs')
-rw-r--r--src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java13
-rw-r--r--src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java6
2 files changed, 15 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java b/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
index e8895c1abf..c70105fb93 100644
--- a/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
+++ b/src/java/org/apache/poi/poifs/crypt/EncryptionInfo.java
@@ -122,8 +122,11 @@ public class EncryptionInfo implements Cloneable {
} else if (
2 <= versionMajor && versionMajor <= 4
&& versionMinor == 2) {
- encryptionMode = (preferredEncryptionMode == cryptoAPI) ? cryptoAPI : standard;
encryptionFlags = dis.readInt();
+ encryptionMode = (
+ preferredEncryptionMode == cryptoAPI
+ || !flagAES.isSet(encryptionFlags))
+ ? cryptoAPI : standard;
} else if (
versionMajor == agile.versionMajor
&& versionMinor == agile.versionMinor){
@@ -268,6 +271,14 @@ public class EncryptionInfo implements Cloneable {
return encryptionMode;
}
+ /**
+ * @return true, if Document Summary / Summary are encrypted and stored in the {@code EncryptedStream} stream,
+ * otherwise the Summaries aren't encrypted and located in their usual streams
+ */
+ public boolean isDocPropsEncrypted() {
+ return !flagDocProps.isSet(getEncryptionFlags());
+ }
+
@Override
public EncryptionInfo clone() throws CloneNotSupportedException {
EncryptionInfo other = (EncryptionInfo)super.clone();
diff --git a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
index 1cc6b1b2f4..8be9ab3faa 100644
--- a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
+++ b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
@@ -51,9 +51,9 @@ public class BinaryRC4Decryptor extends Decryptor implements Cloneable {
super(stream, size, chunkSize);
}
- public BinaryRC4CipherInputStream(InputStream stream)
+ public BinaryRC4CipherInputStream(InputStream stream, int size, int initialPos)
throws GeneralSecurityException {
- super(stream, Integer.MAX_VALUE, chunkSize);
+ super(stream, size, chunkSize, initialPos);
}
}
@@ -141,7 +141,7 @@ public class BinaryRC4Decryptor extends Decryptor implements Cloneable {
@Override
public InputStream getDataStream(InputStream stream, int size, int initialPos)
throws IOException, GeneralSecurityException {
- return new BinaryRC4CipherInputStream(stream);
+ return new BinaryRC4CipherInputStream(stream, size, initialPos);
}