Example #1
0
 private void btnImport_Click(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog())
     {
         ofd.CheckFileExists  = true;
         ofd.Filter           = "*.p12|*.p12";
         ofd.Multiselect      = false;
         ofd.InitialDirectory = Application.StartupPath;
         if (ofd.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 SetCertificate(new X509Certificate2(ofd.FileName, Settings.CertificatePassword, X509KeyStorageFlags.Exportable));
             }
             catch (Exception)
             {
                 try
                 {
                     FrmCertPass CertPassDialog = new FrmCertPass();
                     if (CertPassDialog.ShowDialog(this) == DialogResult.OK)
                     {
                         Settings.CertificatePassword = CertPassDialog.CertPass.Text;
                         SetCertificate(new X509Certificate2(ofd.FileName, Settings.CertificatePassword, X509KeyStorageFlags.Exportable));
                     }
                     CertPassDialog.Dispose();
                 }
                 catch (Exception exception)
                 {
                     MessageBox.Show(this, $"Error importing the certificate:\n{exception.Message}", "Save error",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
 }
Example #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            FrmCertPass CertPassDialog = new FrmCertPass();

            if (CertPassDialog.ShowDialog(this) == DialogResult.OK)
            {
                Settings.CertificatePassword = CertPassDialog.CertPass.Text;
            }
            CertPassDialog.Dispose();
            SetCertificate(CertificateHelper.CreateCertificateAuthority("Quasar Server CA", 4096));
        }