Wrapping Compression and Decryption IO Streams

Hello all,

I am attempting to create a CipherInputStream wrapped inside of a ZipInputStream like this:

CipherInputStream cipherInputStream = new CipherInputStream(fileURL.openStream(),cipher);

ZipInputStream zipInputStream = new ZipInputStream(cipherInputStream);

And then stream the entire file to it's decompressed and decrypted form onto the filesystem.

Theoretically, this seems possible, but it is not working out the way we had hoped and we continually receive a zero-byte file as a result. Is this a matter of block/chunk ordering and a mismatch between the cipher input stream and the zip input stream? Or is it simply not possible, requiring one to finish the decrypting process into a temporary file and then start the decompression?

Any help and/or insight would be most appreciated.

Thanks!

colin schaub

[871 byte] By [bjornsvensona] at [2007-9-19]
# 1

First of all I would suggest to zip and then encrypt.

Second, your problem may be appeared beacuse of problems with concrete padding implemented for the concrete implementation of the concrete algorithm, CipherStream implementation (for example one from Cryptix) may also cause some problems.

euxxa at 2007-7-8 > top of java,Security,Cryptography...
# 2

It works fine for me. Did you remember to call getNextEntry() before reading from the file?

CipherInputStream cyIn = new CipherInputStream(yourInputStreamHere, cipher);

ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); // or any output stream

ZipInputStream zin = new ZipInputStream(cyIn);

zin.getNextEntry();

for ( int i = in.read() ; i != -1 ; i = in.read() ){

out.write(i);

}

zin.close();

rgeimera at 2007-7-8 > top of java,Security,Cryptography...
# 3
Oh my gosh, thank you! That was it - we completely forgot that a ZIP file was an archive rather than just a compressed file. Works perfectly now.colin.
bjornsvensona at 2007-7-8 > top of java,Security,Cryptography...