コード例 #1
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
        //Laddar egen messagebox.
         msgBox MsgBox = new msgBox();

        //Bytar källa beroende på Status på MSGBOX formen. Läses in i if och else satserna.
        BitmapImage bmiOK = new BitmapImage(new Uri("ok_like.png", UriKind.Relative));
        BitmapImage bmiER = new BitmapImage(new Uri("error_cooking.png", UriKind.Relative));

       //kortar ner , ska implenteras i user applications settings senare.
       string contMSGOK = "Compressed & Encrypted!";
       string contMSGER = "A Error was encounted\r\nCheck Log!";
       string rsaErr = "No Key!, Set it before Encrypting";
       string rsaOK = "Keys are Set!";

            if (e.Error != null)
            {
                MsgBox.imgvalid.Source = bmiER;
                MsgBox.txtBlock.Text = contMSGER;
                lstbox1.Items.Add(Environment.NewLine + "Processing folder: " + Environment.NewLine + fileopen.Text + "with total files: " + Environment.NewLine + _totalFileCount + "errors where predicted" + Environment.NewLine + "check settings!");
                MsgBox.ShowDialog();
            }
            else
            {
                settings Sett = new settings();
                //lagrar nycklar i container.
                cspp.KeyContainerName = keyName;
                rsa = new RSACryptoServiceProvider(cspp);
                MsgBox.txtBlock.Text = rsaOK;
                MsgBox.imgvalid.Source = bmiER;
                MsgBox.ShowDialog();

//--------------------------------------------------------------------------------------------------------------------------------------------
// Äldre försök fungerade inte på rätt sett, ingen error handler.
//                //rsa.PersistKeyInCsp = true;
//                if (rsa == null)
//                    lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine);
//                else
//                    lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine);
//----------------------------------------------------------------------------------------------------------------------------------------------

                if (rsa == null)
                {
                    MsgBox.txtBlock.Text = rsaErr;
                    MsgBox.imgvalid.Source = bmiER;    
                    MsgBox.ShowDialog();
                }
                else
                {
                    string fName = EncrFolder + txName.Text + ".henc";
                    //till filhanteringen
                    string oldenc = EncrFolder + txName.Text + ".enc";
                    if (fName != null)
                    {
                        FileInfo fInfo = new FileInfo(fName);
                        // Pass the file name without the path. 
                        string name = fInfo.FullName;
                        EncryptFile(name);
                    }
                    MsgBox.imgvalid.Source = bmiOK;
                    MsgBox.txtBlock.Text = contMSGOK;
                    //skickar status till Loggen...
                    lstbox1.Items.Add(Environment.NewLine + "Folder " + fileopen.Text + "with total: " + _totalFileCount + " files " + Environment.NewLine + "was Compressed and Encrypted" + Environment.NewLine + "Without errors" + Environment.NewLine);
                    //Hanterar gamla och nya encrypterade filer.
                    FileInfo enF = new FileInfo(fName);
                    enF.Delete();
                    FileInfo f = new FileInfo(oldenc);
                    f.CopyTo(fName);
                    f.Delete();
                    prgBar.Value = 0;
                    lstBrow1.Items.Clear();
                    GridVList();
                    this.worker.Dispose();
                    return;
                }
            }
        }
コード例 #2
0
        private void btnprKey_Click(object sender, RoutedEventArgs e)
        {

            //msgBox MsgBox = new msgBox();


            H_ENC___Helix_Encryption.settings settings = new settings();
            settings.ShowDialog();
        }
コード例 #3
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //Laddar egen messagebox.
            msgBox MsgBox = new msgBox();

            //Bytar källa beroende på Status på MSGBOX formen. Läses in i if och else satserna.
            BitmapImage bmiOK = new BitmapImage(new Uri("ok_like.png", UriKind.Relative));
            BitmapImage bmiER = new BitmapImage(new Uri("error_cooking.png", UriKind.Relative));

            //kortar ner , ska implenteras i user applications settings senare.
            string contMSGOK = "Compressed & Encrypted!";
            string contMSGER = "A Error was encounted\r\nCheck Log!";
            string rsaErr    = "No Key!, Set it before Encrypting";
            string rsaOK     = "Keys are Set!";

            if (e.Error != null)
            {
                MsgBox.imgvalid.Source = bmiER;
                MsgBox.txtBlock.Text   = contMSGER;
                lstbox1.Items.Add(Environment.NewLine + "Processing folder: " + Environment.NewLine + fileopen.Text + "with total files: " + Environment.NewLine + _totalFileCount + "errors where predicted" + Environment.NewLine + "check settings!");
                MsgBox.ShowDialog();
            }
            else
            {
                settings Sett = new settings();
                //lagrar nycklar i container.
                cspp.KeyContainerName = keyName;
                rsa = new RSACryptoServiceProvider(cspp);
                MsgBox.txtBlock.Text   = rsaOK;
                MsgBox.imgvalid.Source = bmiER;
                MsgBox.ShowDialog();

//--------------------------------------------------------------------------------------------------------------------------------------------
// Äldre försök fungerade inte på rätt sett, ingen error handler.
//                //rsa.PersistKeyInCsp = true;
//                if (rsa == null)
//                    lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine);
//                else
//                    lstbox1.Items.Add(Environment.NewLine + "Public: " + Environment.NewLine + cspp.KeyContainerName + Environment.NewLine);
//----------------------------------------------------------------------------------------------------------------------------------------------

                if (rsa == null)
                {
                    MsgBox.txtBlock.Text   = rsaErr;
                    MsgBox.imgvalid.Source = bmiER;
                    MsgBox.ShowDialog();
                }
                else
                {
                    string fName = EncrFolder + txName.Text + ".henc";
                    //till filhanteringen
                    string oldenc = EncrFolder + txName.Text + ".enc";
                    if (fName != null)
                    {
                        FileInfo fInfo = new FileInfo(fName);
                        // Pass the file name without the path.
                        string name = fInfo.FullName;
                        EncryptFile(name);
                    }
                    MsgBox.imgvalid.Source = bmiOK;
                    MsgBox.txtBlock.Text   = contMSGOK;
                    //skickar status till Loggen...
                    lstbox1.Items.Add(Environment.NewLine + "Folder " + fileopen.Text + "with total: " + _totalFileCount + " files " + Environment.NewLine + "was Compressed and Encrypted" + Environment.NewLine + "Without errors" + Environment.NewLine);
                    //Hanterar gamla och nya encrypterade filer.
                    FileInfo enF = new FileInfo(fName);
                    enF.Delete();
                    FileInfo f = new FileInfo(oldenc);
                    f.CopyTo(fName);
                    f.Delete();
                    prgBar.Value = 0;
                    lstBrow1.Items.Clear();
                    GridVList();
                    this.worker.Dispose();
                    return;
                }
            }
        }