public static PkwareTraditionalEncryptionData ForRead(string password, ZipFileEntry header, byte[] encryptionHeader) { var encryptor = new PkwareTraditionalEncryptionData(password); byte[] plainTextHeader = encryptor.Decrypt(encryptionHeader, encryptionHeader.Length); if (plainTextHeader[11] != (byte)((header.Crc >> 24) & 0xff)) { if (!FlagUtility.HasFlag(header.Flags, HeaderFlags.UsePostDataDescriptor)) { throw new CryptographicException("The password did not match."); } if (plainTextHeader[11] != (byte)((header.LastModifiedTime >> 8) & 0xff)) { throw new CryptographicException("The password did not match."); } } return(encryptor); }
public override int Read(byte[] buffer, int offset, int count) { if (mode == CryptoMode.Encrypt) { throw new NotSupportedException("This stream does not encrypt via Read()"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } byte[] temp = new byte[count]; int readBytes = stream.Read(temp, 0, count); byte[] decrypted = encryptor.Decrypt(temp, readBytes); Buffer.BlockCopy(decrypted, 0, buffer, offset, readBytes); return(readBytes); }