java - Using streams to decrypt and unzip to limit memory usage? -
I have a very large zip file, 2.5 GB, which is encrypted. I can not decrypt the whole file in memory And do not want to open them there for production. So I'm trying to use the currents to limit the amount of memory used.
I have tilted the following to do this (error handling and stream ending has been left for clarity):
SECRETARY SPECEC keySPEC = new secret of SPEC (mike) "AES"); Cipher cipher = cipher Get Instances ("AES / CBC / PKCS5 Padding"); FileInputStream fis = New FileInputStream (new file (pathToEncryptedFile)); Cipherinputstream cis = new cipher inputstream (fis, cipher); ZipInputStream zis = new ZIPInproststream (new BufferedInputStream (cis)); Zipantries = null; While ((ze = zis.getNextEntry ()) = null) {string filename = ze.getName (); System.out.println ("Enter the zip entry:" + file name); }
This works for approximately 50% of my files, even though they are all zipped and encrypted in the same way. Exception will be found in the loop () for the undefined portion:
java.util.zip.ZipException: Unknown format (EXTSIG = f23f1090) java.util.zip.ZipInputStream on .read andVerifyDataDescriptor (ZipInputStream .java: 196) ...
If I decrypt the whole file in a byte buffer and write it on disk, then use the zip input page on the file, it's all about Works for my exam files.
It seems that there is some problem in using extra padding streams at the end of the encrypted file, but I thought "PKCS 5 padding" specification will keep it in mind.
Thanks
decrypted file Use the ZIP Intestream on Without Reading it in memory If it fails, your file can not be read anyway, and it needs to be recreated (maybe That this is a little non-standard). If it succeeds, then check the results of the decryption stream (before this pinip input) and check the binary difference.
Comments
Post a Comment