本文整理匯總了Java中net.lingala.zip4j.util.Zip4jConstants.AES_STRENGTH_256屬性的典型用法代碼示例。如果您正苦於以下問題:Java Zip4jConstants.AES_STRENGTH_256屬性的具體用法?Java Zip4jConstants.AES_STRENGTH_256怎麽用?Java Zip4jConstants.AES_STRENGTH_256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類net.lingala.zip4j.util.Zip4jConstants
的用法示例。
在下文中一共展示了Zip4jConstants.AES_STRENGTH_256屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: AESEncrpyter
public AESEncrpyter(char[] password, int keyStrength) throws ZipException {
if (password == null || password.length == 0) {
throw new ZipException("input password is empty or null in AES encrypter constructor");
}
if (keyStrength != Zip4jConstants.AES_STRENGTH_128 &&
keyStrength != Zip4jConstants.AES_STRENGTH_256) {
throw new ZipException("Invalid key strength in AES encrypter constructor");
}
this.password = password;
this.keyStrength = keyStrength;
this.finished = false;
counterBlock = new byte[InternalZipConstants.AES_BLOCK_SIZE];
iv = new byte[InternalZipConstants.AES_BLOCK_SIZE];
init();
}
示例2: generateAESExtraDataRecord
private AESExtraDataRecord generateAESExtraDataRecord(ZipParameters parameters) throws ZipException {
if (parameters == null) {
throw new ZipException("zip parameters are null, cannot generate AES Extra Data record");
}
AESExtraDataRecord aesDataRecord = new AESExtraDataRecord();
aesDataRecord.setSignature(InternalZipConstants.AESSIG);
aesDataRecord.setDataSize(7);
aesDataRecord.setVendorID("AE");
// Always set the version number to 2 as we do not store CRC for any AES encrypted files
// only MAC is stored and as per the specification, if version number is 2, then MAC is read
// and CRC is ignored
aesDataRecord.setVersionNumber(2);
if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_128) {
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_128);
} else if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_256) {
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_256);
} else {
throw new ZipException("invalid AES key strength, cannot generate AES Extra data record");
}
aesDataRecord.setCompressionMethod(parameters.getCompressionMethod());
return aesDataRecord;
}
示例3: 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");
}
}
示例4: init
private void init() throws ZipException {
switch (keyStrength) {
case Zip4jConstants.AES_STRENGTH_128:
KEY_LENGTH = 16;
MAC_LENGTH = 16;
SALT_LENGTH = 8;
break;
case Zip4jConstants.AES_STRENGTH_256:
KEY_LENGTH = 32;
MAC_LENGTH = 32;
SALT_LENGTH = 16;
break;
default:
throw new ZipException("invalid aes key strength, cannot determine key sizes");
}
saltBytes = generateSalt(SALT_LENGTH);
byte[] keyBytes = deriveKey(saltBytes, password);
if (keyBytes == null || keyBytes.length != (KEY_LENGTH + MAC_LENGTH + PASSWORD_VERIFIER_LENGTH)) {
throw new ZipException("invalid key generated, cannot decrypt file");
}
aesKey = new byte[KEY_LENGTH];
macKey = new byte[MAC_LENGTH];
derivedPasswordVerifier = new byte[PASSWORD_VERIFIER_LENGTH];
System.arraycopy(keyBytes, 0, aesKey, 0, KEY_LENGTH);
System.arraycopy(keyBytes, KEY_LENGTH, macKey, 0, MAC_LENGTH);
System.arraycopy(keyBytes, KEY_LENGTH + MAC_LENGTH, derivedPasswordVerifier, 0, PASSWORD_VERIFIER_LENGTH);
aesEngine = new AESEngine(aesKey);
mac = new MacBasedPRF("HmacSHA1");
mac.init(macKey);
}
示例5: 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);
}