예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Verify the hash value for a file
        /// </summary>
        /// <param name="InputPath">Encrypted file path</param>
        /// <param name="OutputPath">Decrypted file path</param>
        /// <param name="KeyPath">Full path to key file</param>
        /// <returns>Verified [bool]</returns>
        internal bool Verify(string InputPath, string KeyPath)
        {
            byte[] hashKey = KeyHeader.GetMessageKey(KeyPath);
            byte[] msgHash = MessageHeader.GetMessageHash(InputPath);
            byte[] hash    = GetChecksum(InputPath, hashKey);

            return(IsEqual(msgHash, hash));
        }