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 2023/02/04 20:06:31 UTC

[Bug 66436] After the .xlsx file is encrypted by poi and then decrypted by POI, an error will be reported when it is opened with Microsoft Excel, and an error will also be reported when it is decompressed with commons-compress

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

--- Comment #18 from Dominik Stadler <do...@gmx.at> ---
I could narrow this down to the following test-case and the following findings:

* The length of the byte[] is related, e.g. using 4000 bytes works, but 3292
like here fails
* The actual byte-data seems unrelated, i.e. it fails both when filling the
byte-array with data and also when leaving it empty
* It might be related to some padding, using byte-size 3280 and 3296 make it
work
* It also reproduces with byte-arrays length of 16 (works) and 17 (does not
work)


class TestAgileEncryptor {
    @Test
    void testAgileEncryptor() throws Exception {
        byte[] testData = new byte[3292];

        EncryptionInfo infoEnc = new EncryptionInfo(EncryptionMode.agile);
        Encryptor enc = infoEnc.getEncryptor();
        enc.confirmPassword("foobaa");

        byte[] inputData;
        try (POIFSFileSystem fsEnc = new POIFSFileSystem()) {
            try (OutputStream os = enc.getDataStream(fsEnc)) {
                os.write(testData);
            }

            UnsynchronizedByteArrayOutputStream bos = new
UnsynchronizedByteArrayOutputStream();
            fsEnc.writeFilesystem(bos);

            bos.close();
            inputData = bos.toByteArray();
        }

        byte[] actualData;
        try (POIFSFileSystem fsDec = new POIFSFileSystem(new
ByteArrayInputStream(inputData))) {
            EncryptionInfo infoDec = new EncryptionInfo(fsDec);
            Decryptor dec = infoDec.getDecryptor();
            boolean passed = dec.verifyPassword("foobaa");
            assertTrue(passed);
            InputStream is = dec.getDataStream(fsDec);
            actualData = IOUtils.toByteArray(is);
            is.close();
        }

        assertArrayEquals(testData, actualData,
                "Having " + testData.length + " bytes");
    }
}

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