CertificatesToDBandBack.Certificate.GetCertificateFromPEMstring C# (CSharp) Method

GetCertificateFromPEMstring() public method

public GetCertificateFromPEMstring ( bool certOnly ) : X509Certificate2
certOnly bool
return System.Security.Cryptography.X509Certificates.X509Certificate2
        public X509Certificate2 GetCertificateFromPEMstring(bool certOnly)
        {
            if (certOnly)
                return GetCertificateFromPEMstring(this.PublicCertificate);
            else
                return GetCertificateFromPEMstring(this.PublicCertificate, this.PrivateKey, this.Password);
        }

Same methods

Certificate::GetCertificateFromPEMstring ( string publicCert ) : X509Certificate2
Certificate::GetCertificateFromPEMstring ( string publicCert, string privateKey, string password ) : X509Certificate2

Usage Example

Example #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            IsValid = false;
            Certificate      cert  = new Certificate(txtCer.Text, txtKey.Text, txtPassword.Text);
            X509Certificate2 xcert = null;

            try
            {
                if (string.IsNullOrEmpty(cert.PrivateKey))
                {
                    xcert = cert.GetCertificateFromPEMstring(true);
                }
                else
                {
                    xcert = cert.GetCertificateFromPEMstring(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("An error occure during certificate creation: Error {0}", ex.Message));
                pictureBox1.Image = new Bitmap("red_light.png");
                return;
            }

            pictureBox1.Image = new Bitmap("green_light.png");
            IsValid           = true;
        }