/** * * @param outFile * output file (aes encrypted zip file) */ public AesZipFileEncrypter(File outFile, AESEncrypter encrypter) throws IOException { zipOS = new ExtZipOutputStream(outFile); this.encrypter = encrypter; }
/** * Client is required to call this method after he added all entries so the final archive part is * written. */ public void close() throws IOException { zipOS.finish(); }
protected void add(ExtZipEntry zipEntry, InputStream zipData) throws IOException, UnsupportedEncodingException { zipOS.putNextEntry(zipEntry); byte[] data = new byte[1024]; int read = zipData.read(data); while (read != -1) { zipOS.writeBytes(data, 0, read); read = zipData.read(data); } }
protected void writeDirEntry(ExtZipEntry entry) throws IOException { writeInt(CENSIG); // writeBytes( new byte[] { 0x50, 0x4b, 0x01, 0x02 } // ); // directory signature writeShort(ZIP_VERSION); // version made by writeFileInfo(entry); writeShort(0x00); // file comment length 2 bytes writeShort(0x00); // disk number start (unused) 2 bytes writeShort(0x00); // internal file attributes (unsued) 2 bytes writeInt(0x00); // external file attributes (unused) 4 bytes writeInt(entry.getOffset()); // relative offset of local header 4 bytes writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
InputStream is = null; try { zos = new ExtZipOutputStream( tmpFile ); ExtZipEntry tmpEntry = new ExtZipEntry( zipEntry ); tmpEntry.setPrimaryCompressionMethod( zipEntry.getMethod() ); zos.putNextEntry( tmpEntry ); int read = raFile.readByteArray(buffer,len); decrypter.decrypt( buffer, read ); zos.writeBytes( buffer, 0, read ); remaining -= len; zos.finish(); zos = null; zos.close();
entry.initEncryptedEntry(); zipOS.putNextEntry(entry); zipOS.writeBytes(encrypter.getSalt()); zipOS.writeBytes(encrypter.getPwVerification()); zipOS.writeBytes(data, 0, data.length); + zipOS.getWritten()); zipOS.writeBytes(finalAuthentication);
/** * Finishes writing the contents of the ZIP output stream. */ public void finish() throws IOException { int dirOffset = written; // central directory (at end of zip file) // starts here int startOfCentralDirectory = written; Iterator<ExtZipEntry> it = entries.iterator(); while (it.hasNext()) { ExtZipEntry entry = it.next(); writeDirEntry(entry); } int centralDirectorySize = written - startOfCentralDirectory; writeInt(ENDSIG); // end of central dir signature 4 bytes writeShort(0x00); // number of this disk 2 bytes writeShort(0x00); // number of the disk with the start of the central directory 2 bytes writeShort(entries.size()); // total number of entries in central directory on this disk 2 bytes writeShort(entries.size()); // total number of entries in the central directory 2 bytes writeInt(centralDirectorySize); // size of the central directory 4 bytes writeInt(dirOffset); // offset of start of central dir, with respect to starting disk 4 bytes byte[] commentBytes = this.comment!=null ? this.comment.getBytes() : new byte[0]; writeShort(commentBytes.length); // .ZIP file comment length 2 bytes if( commentBytes.length>0 ) { writeBytes(commentBytes); } out.close(); }
protected void writeExtraBytes(ZipEntry entry) throws IOException { byte[] extraBytes = entry.getExtra(); if (extraBytes != null) { writeBytes(extraBytes); } }
public void setComment( String comment ) { zipOS.setComment(comment); }
InputStream is = null; try { zos = new ExtZipOutputStream( tmpFile ); ExtZipEntry tmpEntry = new ExtZipEntry( zipEntry ); tmpEntry.setPrimaryCompressionMethod( zipEntry.getMethod() ); zos.putNextEntry( tmpEntry ); int read = raFile.readByteArray(buffer,len); decrypter.decrypt( buffer, read ); zos.writeBytes( buffer, 0, read ); remaining -= len; zos.finish(); zos = null; zos.close();
protected void writeDirEntry(ExtZipEntry entry) throws IOException { writeInt(CENSIG); // writeBytes( new byte[] { 0x50, 0x4b, 0x01, 0x02 } // ); // directory signature writeShort(ZIP_VERSION); // version made by writeFileInfo(entry); writeShort(0x00); // file comment length 2 bytes writeShort(0x00); // disk number start (unused) 2 bytes writeShort(0x00); // internal file attributes (unsued) 2 bytes writeInt(0x00); // external file attributes (unused) 4 bytes writeInt(entry.getOffset()); // relative offset of local header 4 bytes writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
entry.initEncryptedEntry(); zipOS.putNextEntry(entry); zipOS.writeBytes(encrypter.getSalt()); zipOS.writeBytes(encrypter.getPwVerification()); zipOS.writeBytes(data, 0, data.length); + zipOS.getWritten()); zipOS.writeBytes(finalAuthentication);
/** * Finishes writing the contents of the ZIP output stream. */ public void finish() throws IOException { int dirOffset = written; // central directory (at end of zip file) // starts here int startOfCentralDirectory = written; Iterator<ExtZipEntry> it = entries.iterator(); while (it.hasNext()) { ExtZipEntry entry = it.next(); writeDirEntry(entry); } int centralDirectorySize = written - startOfCentralDirectory; writeInt(ENDSIG); // end of central dir signature 4 bytes writeShort(0x00); // number of this disk 2 bytes writeShort(0x00); // number of the disk with the start of the central directory 2 bytes writeShort(entries.size()); // total number of entries in central directory on this disk 2 bytes writeShort(entries.size()); // total number of entries in the central directory 2 bytes writeInt(centralDirectorySize); // size of the central directory 4 bytes writeInt(dirOffset); // offset of start of central dir, with respect to starting disk 4 bytes byte[] commentBytes = this.comment!=null ? this.comment.getBytes() : new byte[0]; writeShort(commentBytes.length); // .ZIP file comment length 2 bytes if( commentBytes.length>0 ) { writeBytes(commentBytes); } out.close(); }
protected void writeExtraBytes(ZipEntry entry) throws IOException { byte[] extraBytes = entry.getExtra(); if (extraBytes != null) { writeBytes(extraBytes); } }
public void setComment( String comment ) { zipOS.setComment(comment); }
ExtZipOutputStream zos = new ExtZipOutputStream(bos); ExtZipEntry tmpEntry = new ExtZipEntry(zipEntry); tmpEntry.setPrimaryCompressionMethod(zipEntry.getMethod()); tmpEntry.setCompressedSize(zipEntry.getEncryptedDataSize()); zos.putNextEntry(tmpEntry); raFile.seek(cde.getOffset()); byte[] buffer = new byte[bufferSize]; int read = raFile.readByteArray(buffer, len); decrypter.decrypt(buffer, read); zos.writeBytes(buffer, 0, read); remaining -= len; zos.finish(); byte[] storedMac = new byte[10]; raFile.readByteArray(storedMac, 10);
public void putNextEntry(ExtZipEntry entry) throws IOException { entries.add(entry); entry.setOffset(written); // file header signature writeInt(LOCSIG); writeFileInfo(entry); writeBytes(entry.getName().getBytes("iso-8859-1")); writeExtraBytes(entry); }
protected void add(ZipEntry zipEntry, ZipFileEntryInputStream zipData, String password) throws IOException, UnsupportedEncodingException { encrypter.init(password, 256); ExtZipEntry entry = new ExtZipEntry(zipEntry.getName()); entry.setMethod(zipEntry.getMethod()); entry.setSize(zipEntry.getSize()); entry.setCompressedSize(zipEntry.getCompressedSize() + 28); entry.setTime(zipEntry.getTime()); entry.initEncryptedEntry(); zipOS.putNextEntry(entry); // ZIP-file data contains: 1. salt 2. pwVerification 3. encryptedContent 4. authenticationCode zipOS.writeBytes(encrypter.getSalt()); zipOS.writeBytes(encrypter.getPwVerification()); byte[] data = new byte[1024]; int read = zipData.read(data); while (read != -1) { encrypter.encrypt(data, read); zipOS.writeBytes(data, 0, read); read = zipData.read(data); } byte[] finalAuthentication = encrypter.getFinalAuthentication(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("finalAuthentication=" + Arrays.toString(finalAuthentication) + " at pos=" + zipOS.getWritten()); } zipOS.writeBytes(finalAuthentication); }
protected void add(ExtZipEntry zipEntry, InputStream zipData) throws IOException, UnsupportedEncodingException { zipOS.putNextEntry(zipEntry); byte[] data = new byte[1024]; int read = zipData.read(data); while (read != -1) { zipOS.writeBytes(data, 0, read); read = zipData.read(data); } }
/** * * @param outFile * output file (aes encrypted zip file) */ public AesZipFileEncrypter(File outFile, AESEncrypter encrypter) throws IOException { zipOS = new ExtZipOutputStream(outFile); this.encrypter = encrypter; }