コード例 #1
0
ファイル: MainForm.cs プロジェクト: przpl/CryptZip
        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);
        }
コード例 #2
0
ファイル: FileHeader.cs プロジェクト: przpl/CryptZip
        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);
        }