/** copy all "non-compression" attributes */ public ExtZipEntry(ExtZipEntry entry) { super(entry.getName()); setCompressedSize(entry.getCompressedSize()); setSize(entry.getSize()); setComment(entry.getComment()); setTime(entry.getTime()); setMethod(entry.getMethod()); }
ByteArrayOutputStream bos = null; try { CentralDirectoryEntry cde = zipEntry.getCentralDirectoryEntry(); if (!cde.isAesEncrypted()) { throw new ZipException("only AES encrypted files are supported"); int cryptoHeaderOffset = zipEntry.getOffset() - cde.getCryptoHeaderLength(); byte[] salt = raFile.readByteArray(cryptoHeaderOffset, 16); byte[] pwVerification = raFile.readByteArray(cryptoHeaderOffset + 16, 2); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("\n" + cde.toString()); LOG.finest("offset = " + zipEntry.getOffset()); LOG.finest("cryptoOff = " + cryptoHeaderOffset); LOG.finest("password = " + password + " - " + password.length()); 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]; CRC32 crc32 = new CRC32(); int remaining = (int) zipEntry.getEncryptedDataSize(); while (remaining > 0) { int len = (remaining > buffer.length) ? buffer.length : remaining; tmpEntry.setCrc(crc32.getValue()); zos.finish(); byte[] storedMac = new byte[10];
ExtZipEntry zipEntry = new ExtZipEntry( fileName, cde ); zipEntry.setCompressedSize( cde.getCompressedSize() ); zipEntry.setSize( cde.getUncompressedSize() ); zipEntry.setTime( ExtZipEntry.dosToJavaTime(dosTime) ); zipEntry.setMethod( cde.getActualCompressionMethod() ); zipEntry.setOffset( (int)(cde.getLocalHeaderOffset() + cde.getLocalHeaderSize()) + cde.getCryptoHeaderLength() ); zipEntry.initEncryptedEntry(); } else { zipEntry.setMethod( ZipEntry.DEFLATED ); zipEntry.setPrimaryCompressionMethod( ZipEntry.DEFLATED );
byte[] data = bos.toByteArray(); ExtZipEntry entry = new ExtZipEntry(name); entry.setMethod(ZipEntry.DEFLATED); entry.setSize(inputLen); entry.setCompressedSize(data.length + 28); entry.setTime((new java.util.Date()).getTime()); entry.initEncryptedEntry();
protected void writeFileInfo(ExtZipEntry entry) throws IOException { writeShort(ZIP_VERSION); // version needed to extract // general purpose bit flag - 0x0001 indicates encryption 2 bytes writeShort(entry.getFlag()); writeShort(entry.getPrimaryCompressionMethod()); // primary compression // method - // 0x63==encryption writeInt(entry.getDosTime()); // 2 bytes last mod file time + 2 bytes // last mod file date writeInt(entry.getCrc()); // 28 bytes is the encryption overhead (caused by 256-bit AES key) // 2 bytes pwVerification + 16 bytes SALT + 10 bytes AUTHENTICATION writeInt((int) entry.getCompressedSize()); // compressed size writeInt((int) entry.getSize()); // uncompressed size writeShort(entry.getName().length()); // file name length if (entry.getExtra() != null) { writeShort(entry.getExtra().length); // extra field length } else { writeShort(0); } }
/** * Encrypted files: Note that the value in the "compressed size" fields of * the local file header and the central directory entry is the total size * of all the items listed above. In other words, it is the total size of * the salt value, password verification value, encrypted data, and * authentication code. * * @return data size only */ public long getEncryptedDataSize() { // authentication (10), salt (16), verification (2) return getCompressedSize() - 10 - 16 - 2; }
ByteArrayOutputStream bos = null; try { CentralDirectoryEntry cde = zipEntry.getCentralDirectoryEntry(); if (!cde.isAesEncrypted()) { throw new ZipException("only AES encrypted files are supported"); int cryptoHeaderOffset = zipEntry.getOffset() - cde.getCryptoHeaderLength(); byte[] salt = raFile.readByteArray(cryptoHeaderOffset, 16); byte[] pwVerification = raFile.readByteArray(cryptoHeaderOffset + 16, 2); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("\n" + cde.toString()); LOG.finest("offset = " + zipEntry.getOffset()); LOG.finest("cryptoOff = " + cryptoHeaderOffset); LOG.finest("password = " + password + " - " + password.length()); 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 remaining = (int) zipEntry.getEncryptedDataSize(); while (remaining > 0) { int len = (remaining > buffer.length) ? buffer.length : remaining;
ExtZipEntry zipEntry = new ExtZipEntry( fileName, cde ); zipEntry.setCompressedSize( cde.getCompressedSize() ); zipEntry.setSize( cde.getUncompressedSize() ); zipEntry.setTime( ExtZipEntry.dosToJavaTime(dosTime) ); zipEntry.setMethod( cde.getActualCompressionMethod() ); zipEntry.setOffset( (int)(cde.getLocalHeaderOffset() + cde.getLocalHeaderSize()) + cde.getCryptoHeaderLength() ); zipEntry.initEncryptedEntry(); } else { zipEntry.setMethod( ZipEntry.DEFLATED ); zipEntry.setPrimaryCompressionMethod( ZipEntry.DEFLATED );
byte[] data = bos.toByteArray(); ExtZipEntry entry = new ExtZipEntry(name); entry.setMethod(ZipEntry.DEFLATED); entry.setSize(inputLen); entry.setCompressedSize(data.length + 28); entry.setTime((new java.util.Date()).getTime()); entry.initEncryptedEntry();
protected void writeFileInfo(ExtZipEntry entry) throws IOException { writeShort(ZIP_VERSION); // version needed to extract // general purpose bit flag - 0x0001 indicates encryption 2 bytes writeShort(entry.getFlag()); writeShort(entry.getPrimaryCompressionMethod()); // primary compression // method - // 0x63==encryption writeInt(entry.getDosTime()); // 2 bytes last mod file time + 2 bytes // last mod file date writeInt(entry.getCrc()); // 28 bytes is the encryption overhead (caused by 256-bit AES key) // 2 bytes pwVerification + 16 bytes SALT + 10 bytes AUTHENTICATION writeInt((int) entry.getCompressedSize()); // compressed size writeInt((int) entry.getSize()); // uncompressed size writeShort(entry.getName().length()); // file name length if (entry.getExtra() != null) { writeShort(entry.getExtra().length); // extra field length } else { writeShort(0); } }
/** * Encrypted files: Note that the value in the "compressed size" fields of * the local file header and the central directory entry is the total size * of all the items listed above. In other words, it is the total size of * the salt value, password verification value, encrypted data, and * authentication code. * * @return data size only */ public long getEncryptedDataSize() { // authentication (10), salt (16), verification (2) return getCompressedSize() - 10 - 16 - 2; }
public void extractEntryWithTmpFile( ExtZipEntry zipEntry, File outFile, String password ) throws IOException, ZipException, DataFormatException { checkZipEntry(zipEntry); CentralDirectoryEntry cde = zipEntry.getCentralDirectoryEntry(); if( !cde.isAesEncrypted() ) { throw new ZipException("only AES encrypted files are supported"); int cryptoHeaderOffset = zipEntry.getOffset() - cde.getCryptoHeaderLength(); LOG.finest( "offset = " + zipEntry.getOffset() ); LOG.finest( "cryptoOff = " + cryptoHeaderOffset ); LOG.finest( "password = " + password + " - " + password.length() ); try { zos = new ExtZipOutputStream( tmpFile ); ExtZipEntry tmpEntry = new ExtZipEntry( zipEntry ); tmpEntry.setPrimaryCompressionMethod( zipEntry.getMethod() ); zos.putNextEntry( tmpEntry ); int remaining = (int)zipEntry.getEncryptedDataSize(); while( remaining>0 ) { int len = (remaining>buffer.length) ? buffer.length : remaining;
/** copy all "non-compression" attributes */ public ExtZipEntry(ExtZipEntry entry) { super(entry.getName()); setCompressedSize(entry.getCompressedSize()); setSize(entry.getSize()); setComment(entry.getComment()); setTime(entry.getTime()); setMethod(entry.getMethod()); }
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); }
public void extractEntryWithTmpFile( ExtZipEntry zipEntry, File outFile, String password ) throws IOException, ZipException, DataFormatException { checkZipEntry(zipEntry); CentralDirectoryEntry cde = zipEntry.getCentralDirectoryEntry(); if( !cde.isAesEncrypted() ) { throw new ZipException("only AES encrypted files are supported"); int cryptoHeaderOffset = zipEntry.getOffset() - cde.getCryptoHeaderLength(); LOG.finest( "offset = " + zipEntry.getOffset() ); LOG.finest( "cryptoOff = " + cryptoHeaderOffset ); LOG.finest( "password = " + password + " - " + password.length() ); try { zos = new ExtZipOutputStream( tmpFile ); ExtZipEntry tmpEntry = new ExtZipEntry( zipEntry ); tmpEntry.setPrimaryCompressionMethod( zipEntry.getMethod() ); zos.putNextEntry( tmpEntry ); int remaining = (int)zipEntry.getEncryptedDataSize(); while( remaining>0 ) { int len = (remaining>buffer.length) ? buffer.length : remaining;
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); }
BufAccessibleByteArrayOutputStream bos = null; try { CentralDirectoryEntry cde = zipEntry.getCentralDirectoryEntry(); if (!cde.isAesEncrypted()) { throw new ZipException("only AES encrypted files are supported"); int cryptoHeaderOffset = zipEntry.getOffset() - cde.getCryptoHeaderLength(); byte[] salt = raFile.readByteArray(cryptoHeaderOffset, 16); byte[] pwVerification = raFile.readByteArray(cryptoHeaderOffset + 16, 2); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("\n" + cde.toString()); LOG.finest("offset = " + zipEntry.getOffset()); LOG.finest("cryptoOff = " + cryptoHeaderOffset); LOG.finest("password = " + password + " - " + password.length()); 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 total = (int) zipEntry.getEncryptedDataSize(); int count = 0; int loops = 0;