Java Code Examples for net.lingala.zip4j.model.FileHeader#setEncryptionMethod()
The following examples show how to use
net.lingala.zip4j.model.FileHeader#setEncryptionMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileHeaderFactoryTest.java From zip4j with Apache License 2.0 | 6 votes |
private FileHeader generateFileHeader(long lastModifiedFileTime) { FileHeader fileHeader = new FileHeader(); fileHeader.setVersionNeededToExtract(20); fileHeader.setCompressionMethod(CompressionMethod.STORE); fileHeader.setLastModifiedTime(lastModifiedFileTime); fileHeader.setUncompressedSize(1000L); fileHeader.setFileName(FILE_NAME_IN_ZIP); fileHeader.setFileNameLength(FILE_NAME_IN_ZIP.getBytes(InternalZipConstants.CHARSET_UTF_8).length); fileHeader.setEncrypted(true); fileHeader.setEncryptionMethod(EncryptionMethod.AES); fileHeader.setCrc(1231231L); fileHeader.setCompressedSize(23523L); fileHeader.setGeneralPurposeFlag(new byte[] {2, 28}); fileHeader.setDataDescriptorExists(true); fileHeader.setExtraFieldLength(190); return fileHeader; }
Example 2
Source File: HeaderReader.java From AndroidZip with Apache License 2.0 | 6 votes |
/** * Reads AES Extra Data Record and saves it in the {@link FileHeader} * @param fileHeader * @throws ZipException */ private void readAndSaveAESExtraDataRecord(FileHeader fileHeader) throws ZipException { if (fileHeader == null) { throw new ZipException("file header is null in reading Zip64 Extended Info"); } if (fileHeader.getExtraDataRecords() == null || fileHeader.getExtraDataRecords().size() <= 0) { return; } AESExtraDataRecord aesExtraDataRecord = readAESExtraDataRecord(fileHeader.getExtraDataRecords()); if (aesExtraDataRecord != null) { fileHeader.setAesExtraDataRecord(aesExtraDataRecord); fileHeader.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); } }
Example 3
Source File: HeaderReader.java From zip4j with Apache License 2.0 | 5 votes |
private void readAesExtraDataRecord(FileHeader fileHeader, RawIO rawIO) throws ZipException { if (fileHeader.getExtraDataRecords() == null || fileHeader.getExtraDataRecords().size() <= 0) { return; } AESExtraDataRecord aesExtraDataRecord = readAesExtraDataRecord(fileHeader.getExtraDataRecords(), rawIO); if (aesExtraDataRecord != null) { fileHeader.setAesExtraDataRecord(aesExtraDataRecord); fileHeader.setEncryptionMethod(EncryptionMethod.AES); } }
Example 4
Source File: HeaderWriterIT.java From zip4j with Apache License 2.0 | 5 votes |
private void setFileHeadersAsAesEncrypted(List<FileHeader> fileHeaders, AesKeyStrength aesKeyStrength) { for (FileHeader fileHeader : fileHeaders) { fileHeader.setEncrypted(true); fileHeader.setEncryptionMethod(EncryptionMethod.AES); fileHeader.setAesExtraDataRecord(createAesExtraDataRecord(aesKeyStrength, AesVersion.TWO)); } }
Example 5
Source File: FileHeaderFactory.java From zip4j with Apache License 2.0 | 4 votes |
public FileHeader generateFileHeader(ZipParameters zipParameters, boolean isSplitZip, int currentDiskNumberStart, Charset charset, RawIO rawIO) throws ZipException { FileHeader fileHeader = new FileHeader(); fileHeader.setSignature(HeaderSignature.CENTRAL_DIRECTORY); fileHeader.setVersionMadeBy(determineVersionMadeBy(zipParameters, rawIO)); fileHeader.setVersionNeededToExtract(determineVersionNeededToExtract(zipParameters).getCode()); if (zipParameters.isEncryptFiles() && zipParameters.getEncryptionMethod() == EncryptionMethod.AES) { fileHeader.setCompressionMethod(CompressionMethod.AES_INTERNAL_ONLY); fileHeader.setAesExtraDataRecord(generateAESExtraDataRecord(zipParameters)); fileHeader.setExtraFieldLength(fileHeader.getExtraFieldLength() + InternalZipConstants.AES_EXTRA_DATA_RECORD_SIZE); } else { fileHeader.setCompressionMethod(zipParameters.getCompressionMethod()); } if (zipParameters.isEncryptFiles()) { if (zipParameters.getEncryptionMethod() == null || zipParameters.getEncryptionMethod() == EncryptionMethod.NONE) { throw new ZipException("Encryption method has to be set when encryptFiles flag is set in zip parameters"); } fileHeader.setEncrypted(true); fileHeader.setEncryptionMethod(zipParameters.getEncryptionMethod()); } String fileName = validateAndGetFileName(zipParameters.getFileNameInZip()); fileHeader.setFileName(fileName); fileHeader.setFileNameLength(determineFileNameLength(fileName, charset)); fileHeader.setDiskNumberStart(isSplitZip ? currentDiskNumberStart : 0); if (zipParameters.getLastModifiedFileTime() > 0) { fileHeader.setLastModifiedTime(Zip4jUtil.javaToDosTime(zipParameters.getLastModifiedFileTime())); } else { fileHeader.setLastModifiedTime(Zip4jUtil.javaToDosTime(System.currentTimeMillis())); } //For files added by this library, this attribute will be set after closeEntry is done fileHeader.setExternalFileAttributes(new byte[4]); fileHeader.setDirectory(isZipEntryDirectory(fileName)); if (zipParameters.isWriteExtendedLocalFileHeader() && zipParameters.getEntrySize() == -1) { fileHeader.setUncompressedSize(0); } else { fileHeader.setUncompressedSize(zipParameters.getEntrySize()); } if (zipParameters.isEncryptFiles() && zipParameters.getEncryptionMethod() == EncryptionMethod.ZIP_STANDARD) { fileHeader.setCrc(zipParameters.getEntryCRC()); } fileHeader.setGeneralPurposeFlag(determineGeneralPurposeBitFlag(fileHeader.isEncrypted(), zipParameters, charset)); fileHeader.setDataDescriptorExists(zipParameters.isWriteExtendedLocalFileHeader()); fileHeader.setFileComment(zipParameters.getFileComment()); return fileHeader; }