def decrypt(content_entry, cipher)
      # Zip::Entry.extract writes a 0-length file when trying
      # to extract an encrypted stream, so we read the
      # raw bytes based on the offset and lengths
      decrypted = ''
      File.open(@filename, 'rb') do |zipfile|
        zipfile.seek(
          content_entry.local_header_offset +
            content_entry.calculate_local_header_size
        )
        total_to_read = content_entry.compressed_size

        block_size = 4096
        block_size = total_to_read if block_size > total_to_read

        while (buffer = zipfile.read(block_size))
          decrypted     += cipher.update(buffer)
          total_to_read -= buffer.length

          break if total_to_read == 0

          block_size = total_to_read if block_size > total_to_read
        end
      end

      decrypted + cipher.final
    end
def decrypt(content_entry, cipher)
      # Zip::Entry.extract writes a 0-length file when trying
      # to extract an encrypted stream, so we read the
      # raw bytes based on the offset and lengths
      decrypted = ''
      File.open(@filename, 'rb') do |zipfile|
        zipfile.seek(
          content_entry.local_header_offset +
            content_entry.calculate_local_header_size
        )
        total_to_read = content_entry.compressed_size

        block_size = 4096
        block_size = total_to_read if block_size > total_to_read

        while (buffer = zipfile.read(block_size))
          decrypted     += cipher.update(buffer)
          total_to_read -= buffer.length

          break if total_to_read == 0

          block_size = total_to_read if block_size > total_to_read
        end
      end

      decrypted + cipher.final
    end
def decrypt ( content_entry , cipher ) # Zip::Entry.extract writes a 0-length file when trying # to extract an encrypted stream, so we read the # raw bytes based on the offset and lengths decrypted = '' File . open ( @filename , 'rb' ) do | zipfile | zipfile . seek ( content_entry . local_header_offset + content_entry . calculate_local_header_size ) total_to_read = content_entry . compressed_size block_size = 4096 block_size = total_to_read if block_size > total_to_read while ( buffer = zipfile . read ( block_size ) ) decrypted += cipher . update ( buffer ) total_to_read -= buffer . length break if total_to_read == 0 block_size = total_to_read if block_size > total_to_read end end decrypted + cipher . final end
Block decrypt raw bytes from the zip file based on the cipher
Block decrypt raw bytes from the zip file based on the cipher