예제 #1
0
        // this is a global function for decrypting files
        private void decrypt_files()
        {
            try {
                if (ListView1.Items.Count > 0)
                {
                    password passform = new password();
                    if (passform.ShowDialog(this) == DialogResult.OK)
                    {

                        int total_files = ListView1.Items.Count;
                        int files = 0;
                        foreach (ListViewItem item in ListView1.Items)
                        {
                            if (item.Text.ToString().EndsWith("aes"))
                            {
                                Label6.Text = Path.GetFileName(item.Text.ToString());
                                // we have to setup the crypto functions

                                CryptoFunctions encryption = new CryptoFunctions();

                                encryption.setFile(item.Text.ToString());
                                encryption.setPass(passform.MaskedTextBox1.Text.ToString());
                                encryption.init_progressbar(ProgressBar1);
                                encryption.decrypt();
                                files = files + 1;

                                ProgressBar2.Value = (int)(files / ListView1.Items.Count) * 100;
                            }

                        }

                        // loop though listview and remove anything amd update everything

                        foreach (ListViewItem item in ListView1.Items)
                        {
                            for (int i = 0; i < ListView1.Items.Count; i++)
                            {
                                // checks if the filename in the list box doesn't edit with .aes
                                if (ListView1.Items[i].Text.EndsWith("aes"))
                                {
                                    // okay passed the check, lets add .encrypt to the filename
                                    // also delete the original file
                                    string filename = ListView1.Items[i].Text.ToString();
                                    File.Delete(filename);

                                    ListView1.BeginUpdate();

                                    ListView1.Items.RemoveAt(i);
                                    //  laod icon and add it to the list view;
                                    Icon iconForFile = SystemIcons.WinLogo;
                                    ListViewItem item_fixed = new ListViewItem(filename.Replace(".aes", ""), 1);
                                    item_fixed.ImageIndex = 1;
                                    iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(filename.Replace(".aes", ""));

                                    imageList1.Images.Add(filename.Replace(".aes", ""), iconForFile);
                                    item_fixed.ImageKey = filename.Replace(".aes", "");
                                    item_fixed.Text = filename.Replace(".aes", "").ToString();
                                    ListView1.Items.Add(item_fixed).SubItems.Add("No");
                                    ListView1.EndUpdate();

                                }
                            }
                        }

                        MessageBox.Show("Decryption Successful");
                        // reset the progress barss

                        ProgressBar1.Value = 0;
                        ProgressBar2.Value = 0;
                    }
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        // this is a global function for decrypting files

        private void decrypt_files()
        {
            try {
                if (ListView1.Items.Count > 0)
                {
                    password passform = new password();
                    if (passform.ShowDialog(this) == DialogResult.OK)
                    {
                        int total_files = ListView1.Items.Count;
                        int files       = 0;
                        foreach (ListViewItem item in ListView1.Items)
                        {
                            if (item.Text.ToString().EndsWith("aes"))
                            {
                                Label6.Text = Path.GetFileName(item.Text.ToString());
                                // we have to setup the crypto functions

                                CryptoFunctions encryption = new CryptoFunctions();

                                encryption.setFile(item.Text.ToString());
                                encryption.setPass(passform.MaskedTextBox1.Text.ToString());
                                encryption.init_progressbar(ProgressBar1);
                                encryption.decrypt();
                                files = files + 1;


                                ProgressBar2.Value = (int)(files / ListView1.Items.Count) * 100;
                            }
                        }



                        // loop though listview and remove anything amd update everything

                        foreach (ListViewItem item in ListView1.Items)
                        {
                            for (int i = 0; i < ListView1.Items.Count; i++)
                            {
                                // checks if the filename in the list box doesn't edit with .aes
                                if (ListView1.Items[i].Text.EndsWith("aes"))
                                {
                                    // okay passed the check, lets add .encrypt to the filename
                                    // also delete the original file
                                    string filename = ListView1.Items[i].Text.ToString();
                                    File.Delete(filename);

                                    ListView1.BeginUpdate();



                                    ListView1.Items.RemoveAt(i);
                                    //  laod icon and add it to the list view;
                                    Icon         iconForFile = SystemIcons.WinLogo;
                                    ListViewItem item_fixed  = new ListViewItem(filename.Replace(".aes", ""), 1);
                                    item_fixed.ImageIndex = 1;
                                    iconForFile           = System.Drawing.Icon.ExtractAssociatedIcon(filename.Replace(".aes", ""));


                                    imageList1.Images.Add(filename.Replace(".aes", ""), iconForFile);
                                    item_fixed.ImageKey = filename.Replace(".aes", "");
                                    item_fixed.Text     = filename.Replace(".aes", "").ToString();
                                    ListView1.Items.Add(item_fixed).SubItems.Add("Нет");
                                    ListView1.EndUpdate();
                                }
                            }
                        }

                        MessageBox.Show("Дешифрование успешно завершено");
                        // reset the progress barss

                        ProgressBar1.Value = 0;
                        ProgressBar2.Value = 0;
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }