示例#1
0
        internal void Encrypt(string InputPath, string OutputPath)
        {
            byte[]       hashKey  = KeyHeader.GetMessageKey(this.KeyPath);
            byte[]       checkSum = new byte[64];
            MemoryStream header   = new MemoryStream(MessageHeader.Create(this.KeyPath, Path.GetExtension(InputPath), checkSum));

            this.FileSize     = GetFileSize(InputPath);
            this.IsEncryption = true;

            //calculate progress interval
            CalculateInterval();

            if (this.Engine == Engines.ChaCha || this.Engine == Engines.DCS || this.Engine == Engines.Salsa || this.Engine == Engines.Fusion)
            {
                // stream cipher
                ProcessStream(InputPath, OutputPath, header);
            }
            else
            {
                // init block cipher
                this.Mode.Init(true, new KeyParams(this.Key, this.IV));
                if (this.Mode.Name == "CTR" && this.IsParallel)
                {
                    ParallelCTR(InputPath, OutputPath, header);
                }
                else
                {
                    EncryptFile(InputPath, OutputPath, header);
                }
            }

            // create checksum and sign
            checkSum = GetChecksum(OutputPath, hashKey);
            MessageHeader.SetMessageHash(OutputPath, checkSum);
        }