2

I discovered that Java 7 introduced a zip FileSystem. Currently I have a encrypted zip files, that I'm decrypting with the following code

InputStream in = new FileInputStream(inFile);
Crypto algo = new Crypto();
algo.initV1();
in = new CipherInputStream(in, algo.getCiphertoDec(in, pass));
ZipInputStream zipInput = new ZipInputStream(in);
ZipEntry ze = zipInput.getNextEntry();
....

and the method getCiphertoDec is like this

public Cipher getCiphertoDec (InputStream in, String password) throws Exception {
    byte[] salt = new byte[SALT_SIZE_BYTE];
    if (in.read(salt) < SALT_SIZE_BYTE) {
        throw new IllegalArgumentException("Invalid file length (needs a full block for salt)");
    };

    key = CoreCryptoV1.PBKDF2.pbkdf2(password, salt, 1000);

    ivBytes = new byte[IV_LENGTH_BYTE];
    if (in.read(ivBytes) < IV_LENGTH_BYTE) {
        throw new IllegalArgumentException("Invalid file length (needs a full block for iv)");
    };

    cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivBytes));
    return cipher;
}

I wonder if there is any way to treat encrypted zip file as a file system. I appreciate any advice. I would like a solution that is compatible with android.

user60108
  • 3,270
  • 2
  • 27
  • 43
  • 1
    Given that your decryption method is customized, I doubt it. You could always decrypt the stream to a file on disk and then use the zip `FileSystem` on top of that, but I suspect that defeats whatever reason you had for keeping the zip file encrypted to begin with. – Dan Oct 24 '15 at 07:57
  • @Dan is a rare that zip File System can not be created from an InputStream, that would solve my problem – user60108 Oct 25 '15 at 18:46

0 Answers0