示例#1
0
        private void OnGenerateButtonClick(object?sender, EventArgs e)
        {
            if (_MerchantCertificateRadioButton.Checked)
            {
                _LastGeneratedRSAPrivateKey = new RSACng(2048);

                _LastGeneratedECDsaPrivateKey?.Dispose();
                _LastGeneratedECDsaPrivateKey = null;

                CertificateRequest CertificateRequest = new CertificateRequest(
                    $"E={_EmailAddressTextBox.Text}, CN={_CommonNameTextBox.Text}, O=US",
                    _LastGeneratedRSAPrivateKey,
                    HashAlgorithmName.SHA256,
                    RSASignaturePadding.Pkcs1);
                _LastGeneratedCSRContent = CertificateRequest.CreateSigningRequest();
            }
            else
            {
                _LastGeneratedECDsaPrivateKey = new ECDsaCng(256);

                _LastGeneratedRSAPrivateKey?.Dispose();
                _LastGeneratedRSAPrivateKey = null;

                CertificateRequest CertificateRequest = new CertificateRequest(
                    $"E={_EmailAddressTextBox.Text}, CN={_CommonNameTextBox.Text}, O=US",
                    _LastGeneratedECDsaPrivateKey,
                    HashAlgorithmName.SHA256);
                _LastGeneratedCSRContent = CertificateRequest.CreateSigningRequest();
            }

            _CertificateSigningRequestContentTextBox.Text = CertificateExtensions.EncodeDERDataInPEMFormat(_LastGeneratedCSRContent, "CERTIFICATE REQUEST");

            _ExportCertificateSigningRequestButton.Enabled = true;
        }
示例#2
0
        private void OnImportAndCombineButtonClick(object?sender, EventArgs e)
        {
            using OpenFileDialog OpenFileDialog = new OpenFileDialog
                  {
                      Title    = "Open Certificate",
                      FileName = _MerchantCertificateRadioButton.Checked ? "merchant_id.cer" : "apple_pay.cer",
                      Filter   = "Certificates (*.cer)|*.cer"
                  };

            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                _LastImportedSignedCertificate?.Dispose();

                _LastImportedSignedCertificate = new X509Certificate2(OpenFileDialog.FileName);

                _CertificateContentTextBox.Text = CertificateExtensions.EncodeDERDataInPEMFormat(_LastImportedSignedCertificate.Export(X509ContentType.Cert), "CERTIFICATE");

                _SaveCertificateButton.Enabled = true;
            }
        }