Example #1
0
        public void decrypt()
        {
            // now we use try catch, in the event something bad happens <3

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "RuSimpleCrypt";

                using (FileStream output = new FileStream(@filename.Replace(".aes", ""), FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    byte[] buffer = new byte[1024 * 4];

                    Stream input = new FileStream(@filename, FileMode.Open, FileAccess.Read);
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, input, SharpAESCrypt.OperationMode.Decrypt);
                    long fileLength       = input.Length;
                    long totalBytes       = 0;
                    int  currentBlockSize = 0;



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

                    input.Close();
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void decrypt()
        {
            // now we use try catch, in the event something bad happens <3

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "SimpleCrypt";

                using (FileStream output = new FileStream(@filename.Replace(".aes", ""), FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {

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

                    Stream input = new FileStream(@filename, FileMode.Open, FileAccess.Read);
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, input, SharpAESCrypt.OperationMode.Decrypt);
                    long fileLength = input.Length;
                    long totalBytes = 0;
                    int currentBlockSize = 0;

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

                    input.Close();
                }

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