當前位置: 首頁>>代碼示例>>Java>>正文


Java Zip4jConstants.AES_STRENGTH_192屬性代碼示例

本文整理匯總了Java中net.lingala.zip4j.util.Zip4jConstants.AES_STRENGTH_192屬性的典型用法代碼示例。如果您正苦於以下問題:Java Zip4jConstants.AES_STRENGTH_192屬性的具體用法?Java Zip4jConstants.AES_STRENGTH_192怎麽用?Java Zip4jConstants.AES_STRENGTH_192使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在net.lingala.zip4j.util.Zip4jConstants的用法示例。


在下文中一共展示了Zip4jConstants.AES_STRENGTH_192屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculateAESSaltLength

private int calculateAESSaltLength(AESExtraDataRecord aesExtraDataRecord) throws ZipException {
	if (aesExtraDataRecord == null) {
		throw new ZipException("unable to determine salt length: AESExtraDataRecord is null");
	}
	switch (aesExtraDataRecord.getAesStrength()) {
	case Zip4jConstants.AES_STRENGTH_128:
		return 8;
	case Zip4jConstants.AES_STRENGTH_192:
		return 12;
	case Zip4jConstants.AES_STRENGTH_256:
		return 16;
	default:
		throw new ZipException("unable to determine salt length: invalid aes key strength");
	}
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:15,代碼來源:UnzipEngine.java

示例2: init

private void init(byte[] salt, byte[] passwordVerifier) throws ZipException {
	if (localFileHeader == null) {
		throw new ZipException("invalid file header in init method of AESDecryptor");
	}
	
	AESExtraDataRecord aesExtraDataRecord = localFileHeader.getAesExtraDataRecord();
	if (aesExtraDataRecord == null) {
		throw new ZipException("invalid aes extra data record - in init method of AESDecryptor");
	}
	
	switch (aesExtraDataRecord.getAesStrength()) {
	case Zip4jConstants.AES_STRENGTH_128:
		KEY_LENGTH = 16;
		MAC_LENGTH = 16;
		SALT_LENGTH = 8;
		break;
	case Zip4jConstants.AES_STRENGTH_192:
		KEY_LENGTH = 24;
		MAC_LENGTH = 24;
		SALT_LENGTH = 12;
		break;
	case Zip4jConstants.AES_STRENGTH_256:
		KEY_LENGTH = 32;
		MAC_LENGTH = 32;
		SALT_LENGTH = 16;
		break;
	default:
		throw new ZipException("invalid aes key strength for file: " + localFileHeader.getFileName());
	}
	
	if (localFileHeader.getPassword() == null || localFileHeader.getPassword().length <= 0) {
		throw new ZipException("empty or null password provided for AES Decryptor");
	}
	
	byte[] derivedKey = deriveKey(salt, localFileHeader.getPassword());
	if (derivedKey == null || 
			derivedKey.length != (KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH)) {
		throw new ZipException("invalid derived key");
	}
	
	aesKey = new byte[KEY_LENGTH];
	macKey = new byte[MAC_LENGTH];
	derivedPasswordVerifier = new byte[PASSWORD_VERIFIER_LENGTH];
	
	System.arraycopy(derivedKey, 0, aesKey, 0, KEY_LENGTH);
	System.arraycopy(derivedKey, KEY_LENGTH, macKey, 0, MAC_LENGTH);
	System.arraycopy(derivedKey, KEY_LENGTH + MAC_LENGTH, derivedPasswordVerifier, 0, PASSWORD_VERIFIER_LENGTH);
	
	if (derivedPasswordVerifier == null) {
		throw new ZipException("invalid derived password verifier for AES");
	}
	
	if (!Arrays.equals(passwordVerifier, derivedPasswordVerifier)) {
		throw new ZipException("Wrong Password for file: " + localFileHeader.getFileName(), ZipExceptionConstants.WRONG_PASSWORD);
	}
	
	aesEngine = new AESEngine(aesKey);
	mac = new MacBasedPRF("HmacSHA1");
	mac.init(macKey);
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:60,代碼來源:AESDecrypter.java


注:本文中的net.lingala.zip4j.util.Zip4jConstants.AES_STRENGTH_192屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。