mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Do not fail if an empty password is provided
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1907446 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3eae53357d
commit
25d67aa6ec
@ -538,7 +538,11 @@ public final class CryptoFunctions {
|
||||
// The MS-OFFCRYPTO misses some infos about the various rotation sizes
|
||||
byte[] obfuscationArray = new byte[16];
|
||||
System.arraycopy(passBytes, 0, obfuscationArray, 0, passBytes.length);
|
||||
System.arraycopy(PAD_ARRAY, 0, obfuscationArray, passBytes.length, PAD_ARRAY.length-passBytes.length+1);
|
||||
if (passBytes.length == 0) {
|
||||
System.arraycopy(PAD_ARRAY, 0, obfuscationArray, passBytes.length, PAD_ARRAY.length);
|
||||
} else {
|
||||
System.arraycopy(PAD_ARRAY, 0, obfuscationArray, passBytes.length, PAD_ARRAY.length - passBytes.length + 1);
|
||||
}
|
||||
|
||||
int xorKey = createXorKey1(password);
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.HexRead;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -53,6 +54,23 @@ class TestXorEncryption {
|
||||
assertThat(xorArrExp, equalTo(xorArrAct));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testXorEncryptionEmptyPassword() {
|
||||
// Xor-Password: ""
|
||||
// 2.5.343 XORObfuscation
|
||||
// key = 0
|
||||
// verifier = 0
|
||||
int verifier = CryptoFunctions.createXorVerifier1("");
|
||||
int key = CryptoFunctions.createXorKey1("");
|
||||
assertEquals(0, key);
|
||||
assertEquals(0, verifier);
|
||||
|
||||
byte[] xorArrAct = CryptoFunctions.createXorArray1("");
|
||||
byte[] xorArrExp = HexRead.readFromString("EE-FF-FF-EA-FF-FF-E6-02-00-FA-3C-00-FE-3C-00-00");
|
||||
assertThat("Having: " + HexDump.dump(xorArrAct, 0, 0),
|
||||
xorArrExp, equalTo(xorArrAct));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUserFile() throws IOException {
|
||||
File f = getSampleFile("xor-encryption-abc.xls");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user