You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Chris Bamford <cb...@mimecast.com> on 2010/09/17 13:45:51 UTC

compress - 3 questions about encryption

Hi,

I hope someone can advise me.
I am developing Java code to handle archives using commons compress and am currently focusing on ZIP files.  I understand that ZIPs can be encrypted in two ways:

   (a) the contained entries can be plain text or encrypted
   (b) the whole ZIP itself can be encrypted

QUESTION 1:  Is this correct?  
If so, I need to be able to detect both.  So far I only know how to handle (a), by using this method:

    public boolean checkZipEntryIsEncrypted(ZipArchiveEntry entry) {
        boolean encrypted = false;

        // Check if zip file is encrypted
        if (zfile != null) {
            if (! zfile.canReadEntryData(entry)) {
                encrypted = true;
            }
        }

        return encrypted;
    }

QUESTION 2: is this the right way to detect encrypted entries?

QUESTION 3: what is the right way to detect that the ZIP itself is encrypted?

Thanks,

- Chris


Chris Bamford


2 - 8 Balfe Street
Kings Cross,
London, N1 9EG

mobile 
tel: +44 (0) 207 843 2300
web www.mimecast.com


The information contained in this communication from cbamford@mimecast.com is confidential and may be legally privileged. It is intended solely for use by user@commons.apache.org and others authorized to receive it. If you are not user@commons.apache.org you are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.


Mimecast Ltd. is a company registered in England and Wales with the company number 4698693 VAT No. GB 832 5179 29
Registered Office: 17 Heathman’s Road London, England, SW6 4TJ Email Address: info@mimecast.com

This email message has been scanned for viruses by Mimecast.
Mimecast delivers a complete managed email solution from a single web based platform.
For more information please visit http://www.mimecast.com

Re: compress - 3 questions about encryption

Posted by Chris Bamford <cb...@mimecast.com>.
Thanks Stefan

On 17 Sep 2010, at 13:58, Stefan Bodewig wrote:

> entry.getGeneralPurposeBit().usesEncryption()


Chris Bamford


2 - 8 Balfe Street
Kings Cross,
London, N1 9EG

mobile 
tel: +44 (0) 207 843 2300
web www.mimecast.com


The information contained in this communication from cbamford@mimecast.com is confidential and may be legally privileged. It is intended solely for use by user@commons.apache.org and others authorized to receive it. If you are not user@commons.apache.org you are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.


Mimecast Ltd. is a company registered in England and Wales with the company number 4698693 VAT No. GB 832 5179 29
Registered Office: 17 Heathman’s Road London, England, SW6 4TJ Email Address: info@mimecast.com

This email message has been scanned for viruses by Mimecast.
Mimecast delivers a complete managed email solution from a single web based platform.
For more information please visit http://www.mimecast.com

Re: compress - 3 questions about encryption

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-17, Stefan Bodewig wrote:

> On 2010-09-17, Chris Bamford wrote:

>>     public boolean checkZipEntryIsEncrypted(ZipArchiveEntry entry) {
>>         boolean encrypted = false;

>>         // Check if zip file is encrypted
>>         if (zfile != null) {
>>             if (! zfile.canReadEntryData(entry)) {
>>                 encrypted = true;
>>             }
>>         }

>>         return encrypted;
>>     }

>> QUESTION 2: is this the right way to detect encrypted entries?

> encryption is one of the reasons canReadEntryData may return false,
> another reason could be an unsupported compression algorithm.

maybe I should have told you how to do it correctly?

entry.getGeneralPurposeBit().usesEncryption() will tell you whether an
entry is encrypted - no matter whether it uses the old weak-encryption
mechanism or the more modern approach.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: compress - 3 questions about encryption

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-17, Chris Bamford wrote:

> I am developing Java code to handle archives using commons compress
> and am currently focusing on ZIP files.  I understand that ZIPs can be
> encrypted in two ways:

>    (a) the contained entries can be plain text or encrypted
>    (b) the whole ZIP itself can be encrypted

> QUESTION 1:  Is this correct?

More or less, yes.  (a) is even a bit more complex since there are
different ways an entry can be encrypted (there is an old-style
encryption and a more modern variant that signals the algorithm used).

In either case, Commons Compress doesn't support encryption of ZIPs in
any way.

> So far I only know how to handle (a), by using this method:

>     public boolean checkZipEntryIsEncrypted(ZipArchiveEntry entry) {
>         boolean encrypted = false;

>         // Check if zip file is encrypted
>         if (zfile != null) {
>             if (! zfile.canReadEntryData(entry)) {
>                 encrypted = true;
>             }
>         }

>         return encrypted;
>     }

> QUESTION 2: is this the right way to detect encrypted entries?

encryption is one of the reasons canReadEntryData may return false,
another reason could be an unsupported compression algorithm.

> QUESTION 3: what is the right way to detect that the ZIP itself is
> encrypted?

There isn't any built into Commons Compress ATM.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org