本文整理匯總了Java中net.lingala.zip4j.util.Zip4jConstants.ENC_METHOD_AES屬性的典型用法代碼示例。如果您正苦於以下問題:Java Zip4jConstants.ENC_METHOD_AES屬性的具體用法?Java Zip4jConstants.ENC_METHOD_AES怎麽用?Java Zip4jConstants.ENC_METHOD_AES使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類net.lingala.zip4j.util.Zip4jConstants
的用法示例。
在下文中一共展示了Zip4jConstants.ENC_METHOD_AES屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkParameters
private void checkParameters(ZipParameters parameters) throws ZipException {
if (parameters == null) {
throw new ZipException("cannot validate zip parameters");
}
if ((parameters.getCompressionMethod() != Zip4jConstants.COMP_STORE) &&
parameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
throw new ZipException("unsupported compression type");
}
if (parameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
if (parameters.getCompressionLevel() < 0 && parameters.getCompressionLevel() > 9) {
throw new ZipException("invalid compression level. compression level dor deflate should be in the range of 0-9");
}
}
if (parameters.isEncryptFiles()) {
if (parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_STANDARD &&
parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_AES) {
throw new ZipException("unsupported encryption method");
}
if (parameters.getPassword() == null || parameters.getPassword().length <= 0) {
throw new ZipException("input password is empty or null");
}
} else {
parameters.setAesKeyStrength(-1);
parameters.setEncryptionMethod(-1);
}
}
示例2: checkCRC
public void checkCRC() throws ZipException {
if (fileHeader != null) {
if (fileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
if (decrypter != null && decrypter instanceof AESDecrypter) {
byte[] tmpMacBytes = ((AESDecrypter)decrypter).getCalculatedAuthenticationBytes();
byte[] storedMac = ((AESDecrypter)decrypter).getStoredMac();
byte[] calculatedMac = new byte[InternalZipConstants.AES_AUTH_LENGTH];
if (calculatedMac == null || storedMac == null) {
throw new ZipException("CRC (MAC) check failed for " + fileHeader.getFileName());
}
System.arraycopy(tmpMacBytes, 0, calculatedMac, 0, InternalZipConstants.AES_AUTH_LENGTH);
if (!Arrays.equals(calculatedMac, storedMac)) {
throw new ZipException("invalid CRC (MAC) for file: " + fileHeader.getFileName());
}
}
} else {
long calculatedCRC = crc.getValue() & 0xffffffffL;
if (calculatedCRC != fileHeader.getCrc32()) {
String errMsg = "invalid CRC for file: " + fileHeader.getFileName();
if (localFileHeader.isEncrypted() &&
localFileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
errMsg += " - Wrong Password?";
}
throw new ZipException(errMsg);
}
}
}
}
示例3: write
public void write(byte[] b, int off, int len) throws IOException {
if (len == 0) return;
if (zipParameters.isEncryptFiles() &&
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
if (pendingBufferLength != 0) {
if (len >= (InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength)) {
System.arraycopy(b, off, pendingBuffer, pendingBufferLength,
(InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength));
encryptAndWrite(pendingBuffer, 0, pendingBuffer.length);
off = (InternalZipConstants.AES_BLOCK_SIZE - pendingBufferLength);
len = len - off;
pendingBufferLength = 0;
} else {
System.arraycopy(b, off, pendingBuffer, pendingBufferLength,
len);
pendingBufferLength += len;
return;
}
}
if (len != 0 && len % 16 != 0) {
System.arraycopy(b, (len + off) - (len % 16), pendingBuffer, 0, len % 16);
pendingBufferLength = len % 16;
len = len - pendingBufferLength;
}
}
if (len != 0)
encryptAndWrite(b, off, len);
}
示例4: PartInputStream
public PartInputStream(RandomAccessFile raf, long start, long len, UnzipEngine unzipEngine) {
this.raf = raf;
this.unzipEngine = unzipEngine;
this.decrypter = unzipEngine.getDecrypter();
this.bytesRead = 0;
this.length = len;
this.isAESEncryptedFile = unzipEngine.getFileHeader().isEncrypted() &&
unzipEngine.getFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES;
}
示例5: zip
/**
* 使用給定密碼壓縮指定文件或文件夾到指定位置.
* @param srcFiles 要壓縮的文件或文件夾File
* @param destFile 壓縮文件存放File
* @param charset 編碼方式
* @param passwd 密碼
* @param compressionMethod 壓縮方式【Zip4jConstants類參數】
* @param compressionLevel 壓縮級別【Zip4jConstants類參數】
* @param encryptionMethod 加密方式【Zip4jConstants類參數】
* @throws ZipException
*/
private static void zip(File[] srcFiles,File destFile, String charset,
String passwd, int compressionMethod, int compressionLevel,
int encryptionMethod) throws ZipException {
//創建目標文件父級目錄
FastFile.createParentDirectory(destFile);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(compressionMethod); // 壓縮方式
parameters.setCompressionLevel(compressionLevel); // 壓縮級別
if (StringUtils.isNotBlank(passwd)) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(encryptionMethod); // 加密方式
if(encryptionMethod==Zip4jConstants.ENC_METHOD_AES){//如果加密方式為AES
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
}
parameters.setPassword(passwd.toCharArray());
}
ZipFile zipFile = new ZipFile(destFile);
zipFile.setFileNameCharset(charset);
for(File srcFile : srcFiles){
if (srcFile.isDirectory()) {
zipFile.addFolder(srcFile, parameters);
} else {
zipFile.addFile(srcFile, parameters);
}
}
}
示例6: closeEntry
public void closeEntry() throws IOException, ZipException {
if (this.pendingBufferLength != 0) {
encryptAndWrite(pendingBuffer, 0, pendingBufferLength);
pendingBufferLength = 0;
}
if (this.zipParameters.isEncryptFiles() &&
this.zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
if (encrypter instanceof AESEncrpyter) {
outputStream.write(((AESEncrpyter)encrypter).getFinalMac());
bytesWrittenForThisFile += 10;
totalBytesWritten += 10;
} else {
throw new ZipException("invalid encrypter for AES encrypted file");
}
}
fileHeader.setCompressedSize(bytesWrittenForThisFile);
localFileHeader.setCompressedSize(bytesWrittenForThisFile);
if (zipParameters.isSourceExternalStream()) {
fileHeader.setUncompressedSize(totalBytesRead);
if (localFileHeader.getUncompressedSize() != totalBytesRead) {
localFileHeader.setUncompressedSize(totalBytesRead);
}
}
long crc32 = crc.getValue();
if (fileHeader.isEncrypted()) {
if (fileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
crc32 = 0;
}
}
if (zipParameters.isEncryptFiles() &&
zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
fileHeader.setCrc32(0);
localFileHeader.setCrc32(0);
} else {
fileHeader.setCrc32(crc32);
localFileHeader.setCrc32(crc32);
}
zipModel.getLocalFileHeaderList().add(localFileHeader);
zipModel.getCentralDirectory().getFileHeaders().add(fileHeader);
HeaderWriter headerWriter = new HeaderWriter();
totalBytesWritten += headerWriter.writeExtendedLocalHeader(localFileHeader, outputStream);
crc.reset();
bytesWrittenForThisFile = 0;
encrypter = null;
totalBytesRead = 0;
}