internal void VerifyCrcAfterExtract(Int32 actualCrc32)
{
#if AESCRYPTO
// After extracting, Validate the CRC32
if (actualCrc32 != _Crc32)
{
// CRC is not meaningful with WinZipAES and AES method 2 (AE-2)
if ((Encryption != EncryptionAlgorithm.WinZipAes128 &&
Encryption != EncryptionAlgorithm.WinZipAes256)
|| _WinZipAesMethod != 0x02)
throw new BadCrcException("CRC error: the file being extracted appears to be corrupted. " +
String.Format("Expected 0x{0:X8}, Actual 0x{1:X8}", _Crc32, actualCrc32));
}
// ignore MAC if the size of the file is zero
if (this.UncompressedSize == 0)
return;
// calculate the MAC
if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
WinZipAesCipherStream wzs = _inputDecryptorStream as WinZipAesCipherStream;
_aesCrypto_forExtract.CalculatedMac = wzs.FinalAuthentication;
_aesCrypto_forExtract.ReadAndVerifyMac(this.ArchiveStream); // throws if MAC is bad
// side effect: advances file position.
}
#else
if (actualCrc32 != _Crc32)
throw new BadCrcException("CRC error: the file being extracted appears to be corrupted. " +
String.Format("Expected 0x{0:X8}, Actual 0x{1:X8}", _Crc32, actualCrc32));
#endif
}