Пример #1
0
        private void LoadCertificateButton_Click(object sender, EventArgs e)
        {
            using OpenFileDialog openFileDialog = new OpenFileDialog
                  {
                      InitialDirectory = "C:\\",
                      Filter           = "X509 Certificate|*.crt",
                      FilterIndex      = 1,
                      RestoreDirectory = true
                  };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                using var stream = openFileDialog.OpenFile();
                if (stream != null)
                {
                    using BinaryReader reader = new BinaryReader(stream);
                    byte[] fileContent = reader.ReadBytes(Convert.ToInt32(stream.Length));

                    if (X509CertificateController.IsValid(fileContent))
                    {
                        m_Certificate = fileContent;
                        var signAlg = X509CertificateController.GetCertificateParameters(m_Certificate);

                        X509CertificateParser parser = new X509CertificateParser();
                        CertificateRichTextBox.Text = parser.ReadCertificate(m_Certificate).ToString();
                    }
                    else
                    {
                        DebugRichTextBox.Text = "Current certificate is not valid!";
                    }
                }
            }
        }
 private void VerifyCertificateButton_Click(object sender, EventArgs e)
 {
     if (m_Certificate != null && m_Certificate.Length != 0)
     {
         if (X509CertificateController.IsValid(m_Certificate))
         {
             Valid();
         }
         else
         {
             Invalid();
         }
     }
 }