echandragrg / winzipaes

Automatically exported from code.google.com/p/winzipaes
0 stars 0 forks source link

Cannot directly create an encrypted zip file, but the two-phase approach works. #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Run the following code:

    public void testEncryptZip() throws Exception {
        ExtZipOutputStream zip = new ExtZipOutputStream(new
File("encOut.zip"));
        String password = "foo";
        AESEncrypter aesEncrypter = new
AESEncrypterBC(password.getBytes("iso-8859-1"));

        long time = System.currentTimeMillis();
        ExtZipEntry entry = new ExtZipEntry(time + ".txt");
        entry.setMethod(ZipOutputStream.DEFLATED);
        entry.setTime(time);
        entry.initEncryptedEntry();

        zip.putNextEntry(entry);
        zip.writeBytes(aesEncrypter.getSalt());
        zip.writeBytes(aesEncrypter.getPwVerification());

        // put some junk in the file
        byte[] data = new byte[1024];
        for (int i=0; i<data.length; i++) {
            data[i] = (byte)(i % 256);
        }
        aesEncrypter.encrypt(data, data.length);
        zip.writeBytes(data, 0, data.length);
        zip.writeBytes(aesEncrypter.getFinalAuthentication());

        zip.finish();
    }

What is the expected output? What do you see instead?
I was hoping to see an encrypted zip file with extractable contents. 
Instead, what I see inside the zip file is an encrypted text file that
cannot be extracted.  When I try to extract it via Winzip 9 and enter the
password, I get "Error: invalid compressed data to inflate".  It shows the
file as having 4294967295 bytes.

The example in AesZipFileEncrypter.java works fine, but it uses a two-phase
approach where a zip file is first created in the first phase and then
later encrypted in the net phase creating two zip files.  What I want to do
is write the content directly to an encrypted zip file.  Is this possible
yet or am I doing it wrong?  

Thanks.

What version of the product are you using? On what operating system?
Downloaded Oct 3rd version of winzipaes.

Please provide any additional information below.

Original issue reported on code.google.com by jackc...@gmail.com on 21 Oct 2009 at 11:58

GoogleCodeExporter commented 8 years ago
The current implementation always requires the "2 phase" approach for creating 
an
encrypted zip file. Reason: it's quite easy to create a zip file by using
java.util.zip and encrypting its contents afterwards as the encrypted data is of
excatly the same size as the zipped data.

Original comment by olaf.merkert on 22 Oct 2009 at 6:39

GoogleCodeExporter commented 8 years ago
Thanks for the quick reply.  I'll continue to use the 2-phase approach

Original comment by jackc...@gmail.com on 22 Oct 2009 at 8:23

GoogleCodeExporter commented 8 years ago
What is the problem?

Original comment by ASWE...@gmail.com on 21 Sep 2013 at 2:02