SevenZipArchiveEntry ignores the password provided to the SevenZipArchive

In Aspose Zip Java I obtain a SevenZipArchive with this method:

@Override
    protected SevenZipArchive getArchive() {
        return decryptionPassword == null ? new SevenZipArchive(zipInputStream) : new SevenZipArchive(zipInputStream, decryptionPassword);
    }

I then iterate the entries with:

archive.getEntries().iterator()

I am sure that in the first snipped the decryptionPassword is set and correct, but when I do:

((SevenZipArchiveEntry) currentZipEntry).open()

I get the error about passing null as password and the only solution I found is:

((SevenZipArchiveEntry) currentZipEntry).open(decryptionPassword)

I don’t understand why I should pass the password each time even if I already specified one in the SevenZipArchive instantiation. In addition, other formats such as zip, do not need to pass the password each time to each entry.

@mrossi

It seems that you are encountering an issue where the password provided during the instantiation of the SevenZipArchive is not being recognized when you attempt to open individual entries. This behavior can be confusing, especially since other archive formats like ZIP do not require the password to be passed for each entry.

In the case of SevenZipArchive, it appears that the design requires you to specify the password each time you open an entry. This is likely due to the way the library handles password management for different entries within the archive. While you have set the password during the creation of the SevenZipArchive, the library may not retain this password for subsequent operations on individual entries.

To resolve this, you will need to continue passing the password when calling the open() method on each SevenZipArchiveEntry, as you have done in your example:

((SevenZipArchiveEntry) currentZipEntry).open(decryptionPassword);

This ensures that the correct password is used for each entry, which is necessary for decryption.

If you find this behavior to be a limitation or a bug, it may be worth reporting it to the Aspose support team for further investigation. They may be able to provide additional insights or consider this for future updates.

If you have any further questions or need additional assistance, feel free to ask!

Hello @mrossi, your observation is correct. It is confusing behavior, and we’ll change it. It happens because filenames of 7z archive (i. e. headers) can also be encrypted, and their password could be different.