Exemplo n.º 1
0
        private void Pack()
        {
            Packer packer = null;

            if (compressCheckBox.Checked && encryptCheckBox.Checked)
            {
                packer = new FullPacker();
            }
            else if (compressCheckBox.Checked)
            {
                packer = new CompressionPacker();
            }
            else if (encryptCheckBox.Checked)
            {
                packer = new EncryptionPacker();
            }

            packer.Compressor = GetCompressor();
            ICipher cipher = GetCipher();

            packer.Encryptor      = GetEncryptor(cipher);
            packer.StatusChanged += OnStatusChanged;
            packer.WorkFinished  += OnWorkFinished;

            SwitchControls(false);
            packer.PackAsync(_filePath);
        }
Exemplo n.º 2
0
        public Packer GetPacker(string path, byte[] key = null)
        {
            Packer packer = null;

            using (var input = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                byte mode = Convert.ToByte(input.ReadByte());

                if (mode == Mode.Full)
                {
                    packer            = new FullPacker();
                    packer.Compressor = GetCompressor(input.ReadByte());
                    ICipher cipher = GetCipher(input.ReadByte(), key);
                    packer.Encryptor = GetEncryptor(input.ReadByte(), cipher, input);
                }
                else if (mode == Mode.Compress)
                {
                    packer = new CompressionPacker {
                        Compressor = GetCompressor(input.ReadByte())
                    }
                }
                ;
                else if (mode == Mode.Encrypt)
                {
                    packer = new EncryptionPacker();
                    ICipher cipher = GetCipher(input.ReadByte(), key);
                    packer.Encryptor        = GetEncryptor(input.ReadByte(), cipher, input);
                    packer.Encryptor.Cipher = cipher;
                }
                else
                {
                    throw new InvalidOperationException("Invalid file header");
                }
            }

            return(packer);
        }