예제 #1
0
        public void encrypt()
        {
            // we do this to handle any errors

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "RuSimpleCrypt";
                using (FileStream output = new FileStream(@filename + ".aes", FileMode.Create, FileAccess.ReadWrite))
                {
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, output, SharpAESCrypt.OperationMode.Encrypt);
                    // now we set the extension information

                    byte[] buffer = new byte[1024 * 4];

                    using (FileStream input = new FileStream(@filename, FileMode.Open, FileAccess.Read))
                    {
                        long fileLength       = input.Length;
                        long totalBytes       = 0;
                        int  currentBlockSize = 0;

                        while ((currentBlockSize = input.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            totalBytes += currentBlockSize;
                            percentage  = (double)totalBytes * 100.0 / fileLength;
                            update_progressbar(percentage);

                            aesStream.Write(buffer, 0, currentBlockSize);
                        }

                        aesStream.FlushFinalBlock();
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        public void encrypt()
        {
            // we do this to handle any errors

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "SimpleCrypt";
                using (FileStream output = new FileStream(@filename + ".aes", FileMode.Create, FileAccess.ReadWrite))
                {
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, output, SharpAESCrypt.OperationMode.Encrypt);
                    // now we set the extension information

                    byte[] buffer = new byte[1024 * 4];

                    using (FileStream input = new FileStream(@filename, FileMode.Open, FileAccess.Read))
                    {

                        long fileLength = input.Length;
                        long totalBytes = 0;
                        int currentBlockSize = 0;

                        while ((currentBlockSize = input.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            totalBytes += currentBlockSize;
                            percentage = (double)totalBytes * 100.0 / fileLength;
                            update_progressbar(percentage);

                            aesStream.Write(buffer, 0, currentBlockSize);
                        }

                        aesStream.FlushFinalBlock();

                    }

                }

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }