private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!isConfigInitialSetup())
            {
                MessageBox.Show("Select YES if you have setup config file", ut.DialogHeader);
            }
            else
            {
                if (isEncryptionContainerKeyReady())
                {
                    //Set Rsa provider name
                    ut.getRsaProviderName = txtRsaProviderName.Text;

                    if (isEncryptionConfigSectionReady())
                    {
                        //
                        progressBar1.Visible = true;
                        progressBar1.Refresh();
                        progressBar1.Minimum = 0;
                        progressBar1.Maximum = 100;

                        lblMsg.Visible = true;
                        lblMsg.Refresh();

                        try
                        {
                            //Do something...
                            string command = String.Empty;

                            //5: Configuration File Encription
                            //5b: App Settings
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef appSettings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxAppSettings.Checked)
                            {
                                string encryptAppSettings = ut.frameworkPrefix + " -pef appSettings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptAppSettings, ut.getFolderPath);
                            }
                            progressBar1.Value += 33;

                            //5b: Connection Strings Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef connectionStrings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxConnectionString.Checked)
                            {
                                string encryptConnectionStrings = ut.frameworkPrefix + " -pef connectionStrings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptConnectionStrings, ut.getFolderPath);
                            }
                            progressBar1.Value += 33;

                            //5c: Identity/Impersonate Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef system.web/identity C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxIdentity.Checked)
                            {
                                string encryptIdentity = ut.frameworkPrefix + " -pef system.web/identity " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync((object)encryptIdentity, ut.getFolderPath);
                            }
                            progressBar1.Value += 33;

                            //Notification
                            MessageBox.Show("DONE! \n Check the folder.", ut.DialogHeader);

                            //Reset form
                            ResetForm();

                            //Close the form
                            this.Close();
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ut.UnknownException + "\n" + ex.Message, ut.DialogHeader);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Check at least one section to be encrypted!", ut.DialogHeader);
                    }
                }
                else
                {
                    MessageBox.Show("Please complete all the required fields!", ut.DialogHeader);
                }
            }
        }
Пример #2
0
        private void btnCreateEncryption_Click(object sender, EventArgs e)
        {
            if (!isConfigInitialSetup())
            {
                MessageBox.Show("Select YES if you have setup config file", ut.DialogHeader);
            }
            else
            {
                if (isEncryptionContainerKeyReady())
                {
                    if (isEncryptionConfigSectionReady())
                    {
                        //
                        progressBar1.Visible = true;
                        progressBar1.Refresh();
                        progressBar1.Minimum = 0;
                        progressBar1.Maximum = 100;

                        lblMsg.Visible = true;
                        lblMsg.Refresh();

                        try
                        {
                            //Do something...
                            string command = String.Empty;
                            ut.getRsaKeyContainerName = txtEncryptionRsaKeyContainerName.Text.Trim();
                            ut.getImpersonate         = txtEncryptionImpersonateName.Text.Trim();
                            ut.getRsaProviderName     = txtEncryptionRsaProviderName.Text.Trim();
                            string keyFileName = ut.getRsaKeyContainerName + ".xml";
                            string msg         = String.Format("Key Container Name: {0}\n Key File Name: {1}\n Impersonate: {2}", ut.getRsaKeyContainerName, keyFileName, ut.getImpersonate);
                            if (chkBoxEncryptionAppSettings.Checked)
                            {
                                msg += "\n Encrypt App Settings";
                            }
                            if (chkBoxEncryptionConnectionString.Checked)
                            {
                                msg += "\n Encrypt Connection Strings";
                            }
                            if
                            (chkBoxEncryptionIdentity.Checked)
                            {
                                msg += "\n Encrypt Impersonate";
                            }

                            // Get the command you wish to execute.
                            command = "mkdir " + ut.getFolderPath + "\\Sample-Folder\\dir";

                            //// Execute the command synchronously.
                            ///Local
                            //ExecuteCommand cmd = new ExecuteCommand();
                            //cmd.ExecuteSync(command);

                            // Execute the command asynchronously.
                            //cmd.ExecuteAsync(command);
                            //MessageBox.Show("Encryption: \n" + msg, ut.DialogHeader);

                            //Container Setup
                            //1: Create a machine - level RSA Key Container
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis - pc "PSConfigurationKeys" -exp
                            string createContainer = ut.frameworkPrefix + " -pc " + ut.getRsaKeyContainerName + " -exp";
                            cmd.ExecuteSync(createContainer, ut.getFolderPath);
                            progressBar1.Value += 12;

                            //2: Exporting the Custom RSA Encryption Key
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319 > aspnet_regiis -px "PSConfigurationKeys" "C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles\PSConfigurationKeys.xml" -pri
                            string RsaKeyFilePath   = ut.getFolderPath + "\\" + ut.getRsaKeyContainerName + ".xml";
                            string createRsaKeyFile = ut.frameworkPrefix + " -px " + ut.getRsaKeyContainerName + " " + RsaKeyFilePath + " -pri";
                            cmd.ExecuteSync(createRsaKeyFile, ut.getFolderPath);
                            progressBar1.Value += 12;

                            //3: Importing the Certificate
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pi "PSConfigurationKeys" "C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles\PSConfigurationKeys.xml"
                            string importCertificate = ut.frameworkPrefix + " -pi " + ut.getRsaKeyContainerName + " " + RsaKeyFilePath;
                            cmd.ExecuteSync(importCertificate, ut.getFolderPath);
                            progressBar1.Value += 12;

                            //4: Adding Permissions to the Certificate
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pa "PSConfigurationKeys" "NT Authority\NETWORK SERVICE" –full
                            string certificatePermission = ut.frameworkPrefix + " -pa " + ut.getRsaKeyContainerName + " NT Authority\\NETWORK SERVICE -full";
                            cmd.ExecuteSync(certificatePermission, ut.getFolderPath);
                            progressBar1.Value += 12;

                            //Due to Ristriction on the Network section --- Tried below but didn't work

                            /*
                             * //-Run aspnet_regiis.exe - i
                             * //- Run aspnet_regiis.exe - ga "NT Authority\Network Service"(NT Authority\Network Service refers to Domain\administrator).
                             *
                             * cmd.ExecuteSync(ut.frameworkPrefix + " -i");
                             * cmd.ExecuteSync(ut.frameworkPrefix + " -ga " + ut.getRsaKeyContainerName + " 'NT Authority\\Network Service' -full");
                             */

                            //4b: Add access to the impersonate user (if applicable)
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pa "PSConfigurationKeys" "impersonate username" -full
                            if (ut.getImpersonate.Length > 0)
                            {
                                string impersonatePermission = ut.frameworkPrefix + " -pa " + ut.getRsaKeyContainerName + " " + ut.getImpersonate + " -full";
                                cmd.ExecuteSync(impersonatePermission, ut.getFolderPath);
                            }
                            progressBar1.Value += 12;

                            //5: Configuration File Encription
                            //5b: App Settings
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef appSettings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxEncryptionAppSettings.Checked)
                            {
                                string encryptAppSettings = ut.frameworkPrefix + " -pef appSettings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptAppSettings, ut.getFolderPath);
                            }
                            progressBar1.Value += 12;

                            //5b: Connection Strings Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef connectionStrings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxEncryptionConnectionString.Checked)
                            {
                                string encryptConnectionStrings = ut.frameworkPrefix + " -pef connectionStrings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptConnectionStrings, ut.getFolderPath);
                            }
                            progressBar1.Value += 12;

                            //5c: Identity/Impersonate Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef system.web/identity C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxEncryptionIdentity.Checked)
                            {
                                string encryptIdentity = ut.frameworkPrefix + " -pef system.web/identity " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync((object)encryptIdentity, ut.getFolderPath);
                            }
                            progressBar1.Value += 14;

                            //Notification
                            MessageBox.Show("DONE! \n Check the folder.", ut.DialogHeader);

                            //Reset form
                            ResetForm();

                            //Close the form
                            this.Close();
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ut.UnknownException + "\n" + ex.Message, ut.DialogHeader);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Check at least one section to be encrypted!", ut.DialogHeader);
                    }
                    //MessageBox.Show("Encryption Container Key is Ready...");
                }
                else
                {
                    MessageBox.Show("Please complete all the required fields!", ut.DialogHeader);
                }
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!isConfigInitialSetup())
            {
                MessageBox.Show("Select YES if you have setup config file", ut.DialogHeader);
            }
            else
            {
                if (isEncryptionContainerKeyReady())
                {
                    //Set names
                    ut.getRsaProviderName     = txtRsaProviderName.Text.Trim();
                    ut.getRsaKeyContainerName = txtRsaKeyName.Text.Trim();
                    ut.getImpersonate         = txtImpersonateName.Text.Trim();

                    if (isEncryptionConfigSectionReady())
                    {
                        //
                        progressBar1.Visible = true;
                        progressBar1.Refresh();
                        progressBar1.Minimum = 0;
                        progressBar1.Maximum = 100;

                        lblMsg.Visible = true;
                        lblMsg.Refresh();

                        try
                        {
                            //Do something...
                            string command = String.Empty;

                            //Local
                            //ExecuteCommand cmd = new ExecuteCommand();

                            //Skip Container setup 1 & 2 commands
                            //C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles\PSConfigurationKeys.xml
                            string RsaKeyFilePath = ut.getFolderPath + "\\" + ut.getRsaKeyContainerName + ".xml";

                            //3: Importing the Certificate
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pi "PSConfigurationKeys" "C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles\PSConfigurationKeys.xml"
                            string importCertificate = ut.frameworkPrefix + " -pi " + ut.getRsaKeyContainerName + " " + RsaKeyFilePath;
                            cmd.ExecuteSync(importCertificate, ut.getFolderPath);
                            progressBar1.Value += 16;

                            //4: Adding Permissions to the Certificate
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pa "PSConfigurationKeys" "NT Authority\NETWORK SERVICE" –full
                            string certificatePermission = ut.frameworkPrefix + " -pa " + ut.getRsaKeyContainerName + " NT Authority\\NETWORK SERVICE -full";
                            cmd.ExecuteSync(certificatePermission, ut.getFolderPath);
                            progressBar1.Value += 16;

                            //4b: Add access to the impersonate user (if applicable)
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pa "PSConfigurationKeys" "impersonate username" -full
                            if (ut.getImpersonate.Length > 0)
                            {
                                string impersonatePermission = ut.frameworkPrefix + " -pa " + ut.getRsaKeyContainerName + " " + ut.getImpersonate + " -full";
                                cmd.ExecuteSync(impersonatePermission, ut.getFolderPath);
                            }
                            progressBar1.Value += 16;

                            //Delete Files???
                            //del C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles\PSConfigurationKeys.xml /f /s /q /a
                            string deleteKeyFile = "del " + RsaKeyFilePath + " /f /s /q /a";
                            //cmd.ExecuteSync(deleteKeyFile, ut.getFolderPath);

                            //5: Configuration File Encription
                            //5b: App Settings
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef appSettings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxAppSettings.Checked)
                            {
                                string encryptAppSettings = ut.frameworkPrefix + " -pef appSettings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptAppSettings, ut.getFolderPath);
                            }
                            progressBar1.Value += 16;

                            //5b: Connection Strings Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef connectionStrings C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxConnectionString.Checked)
                            {
                                string encryptConnectionStrings = ut.frameworkPrefix + " -pef connectionStrings " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync(encryptConnectionStrings, ut.getFolderPath);
                            }
                            progressBar1.Value += 16;

                            //5c: Identity/Impersonate Encryption
                            //> C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -pef system.web/identity C:\Win2k8ElimApp\PSConfiguration-Application\EncryptionFiles -prov "PSConfigurationRsaProvider"
                            if (chkBoxIdentity.Checked)
                            {
                                string encryptIdentity = ut.frameworkPrefix + " -pef system.web/identity " + ut.getFolderPath + " -prov " + ut.getRsaProviderName;
                                cmd.ExecuteSync((object)encryptIdentity, ut.getFolderPath);
                            }
                            progressBar1.Value += 18;

                            //Notification
                            MessageBox.Show("DONE! \n Check the folder.", ut.DialogHeader);

                            //Reset form
                            ResetForm();

                            //Close the form
                            this.Close();
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ut.UnknownException + "\n" + ex.Message, ut.DialogHeader);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Check at least one section to be encrypted!", ut.DialogHeader);
                    }
                }
                else
                {
                    MessageBox.Show("Please complete all the required fields!", ut.DialogHeader);
                }
            }
        }