Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                certFile = File.ReadAllBytes(openFileDialog.FileName);
                if (certFile == null)
                {
                    MessageBox.Show("File is empty");
                }
                else
                {
                    try
                    {
                        model = CertificateReader.Read(certFile);
                        ShowForm showForm = new ShowForm();
                        showForm.richTextBox1.Text = $"Name is {model.Name} \n Issuer is {model.Issuer} \n ValidTo is {model.ValidTo} \n Valid From is {model.ValidFrom}";
                        showForm.Show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.GetBaseException().ToString());
                    }
                }
            }
        }
Esempio n. 2
0
        public static CertificateModel Read(string rawData)
        {
            var              certificate      = new X509Certificate2(Convert.FromBase64String(rawData));
            RSACng           rsa              = certificate.GetRSAPublicKey() as RSACng;
            CertificateModel certificateModel = new CertificateModel
            {
                Name      = certificate.SubjectName.Name,
                Issuer    = certificate.Issuer,
                ValidTo   = certificate.GetExpirationDateString(),
                ValidFrom = certificate.GetEffectiveDateString(),
                PubKey    = Convert.ToBase64String(rsa?.ExportSubjectPublicKeyInfo() ?? certificate.GetPublicKey(), Base64FormattingOptions.InsertLineBreaks)
            };

            return(certificateModel);
        }
Esempio n. 3
0
 private void btnText_Clicked(object sender, EventArgs e)
 {
     if (richTextBox1.Text == string.Empty)
     {
         MessageBox.Show("textbox is empty");
     }
     else
     {
         try
         {
             model = CertificateReader.Read(richTextBox1.Text.Trim());
             ShowForm showForm = new ShowForm();
             showForm.richTextBox1.Text = $"Name is {model.Name} \n Issuer is {model.Issuer} \n ValidTo is {model.ValidTo} \n Valid From is {model.ValidFrom}";
             showForm.Show();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.GetBaseException().ToString());
         }
     }
 }
Esempio n. 4
0
        private async void btnUrl_Clicked(object sender, EventArgs e)
        {
            var url = textBox1.Text.Trim();

            if (url == string.Empty)
            {
                MessageBox.Show("No URL Found");
            }
            else
            {
                if (!url.StartsWith("https"))
                {
                    if (!url.StartsWith("http"))
                    {
                        url = "https://" + url;
                    }
                    else
                    {
                        url = "https:" + url.Split(':')[1];
                    }
                }
                HttpClient httpClient = new HttpClient(new HttpClientHandler
                {
                    UseDefaultCredentials = true,
                    ServerCertificateCustomValidationCallback = (sender, cert, chain, error) =>
                    {
                        model = CertificateReader.Read(cert.RawData);
                        return(true);
                    }
                });
                await httpClient.GetAsync(url);

                if (model != null)
                {
                    ShowForm showForm = new ShowForm();
                    showForm.richTextBox1.Text = $"Name is {model.Name} \n Issuer is {model.Issuer} \n ValidTo is {model.ValidTo} \n Valid From is {model.ValidFrom}";
                    showForm.Show();
                }
            }
        }