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 static PkwareTraditionalEncryptionData ForRead(string password, ZipFileEntry header, byte[] encryptionHeader) { PkwareTraditionalEncryptionData data = new PkwareTraditionalEncryptionData(password); byte[] buffer = data.Decrypt(encryptionHeader, encryptionHeader.Length); if (buffer[11] != ((byte) ((header.Crc >> 0x18) & 0xff))) { if (!FlagUtility.HasFlag<HeaderFlags>(header.Flags, HeaderFlags.UsePostDataDescriptor)) { throw new CryptographicException("The password did not match."); } if (buffer[11] != ((byte) ((header.LastModifiedTime >> 8) & 0xff))) { throw new CryptographicException("The password did not match."); } } return data; }
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); }