示例#1
0
        private void createBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(subjTextBox.Text) && !string.IsNullOrEmpty(fNameTextBox.Text) && ExpirationDate.HasValue)
            {
                NewCertificate.HashAlgorithm hashAl = NewCertificate.GetHashFromString(algoComboBox.SelectedValue);
                int kLen   = Convert.ToInt32(((System.Windows.Controls.ComboBoxItem)keyLenComboBox.SelectedValue).Content);
                var strCtx = (StoreLocation)storeComboBox.SelectedIndex + 1;

                nc = new NewCertificate(subjTextBox.Text, fNameTextBox.Text,
                                        ExpirationDate.Value, hashAl,
                                        (NewCertificate.KeyLengths)kLen, strCtx);

                try
                {
                    X509Certificate2 cert = nc.GenerateCertificate();
                    NewCert = new CertListItem(cert);
                    System.Windows.MessageBox.Show("A new self-signed certificate has been successfully created!",
                                                   "SUCCESS", MessageBoxButton.OK, MessageBoxImage.None);
                    Close();
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message, "ERROR!",
                                                   MessageBoxButton.OK, MessageBoxImage.Error);
                    FlipDateTimeButton(DateTimeButtonOptions.On);
                    return;
                }
            }
        }
        private void pfxInstallerBtn_Click(object sender, RoutedEventArgs e)
        {
            switch (Context)
            {
            case CertContext.User:
                usingStore = StoreLocation.CurrentUser;
                break;

            case CertContext.Machine:
                usingStore = StoreLocation.LocalMachine;
                break;
            }
            X509Certificate2 cert = SharedPrompt.PfxPrompt(usingStore);

            if (cert != null)
            {
                var certListItem = new CertListItem(cert);
                CommitToCert(certListItem);
            }
        }
 private void CommitToCert(CertListItem cert)
 {
     SelectedCert = cert;
     DialogResult = true;
     Close();
 }