Opc.Ua.Configuration.CreateCertificateDlg.UpdateWithCertificate C# (CSharp) Method

UpdateWithCertificate() private method

Updates controls with the certificate.
private UpdateWithCertificate ( X509Certificate2 certificate ) : void
certificate X509Certificate2
return void
        private void UpdateWithCertificate(X509Certificate2 certificate)
        {
            int index = 0;

            if (certificate != null)
            {
                StringBuilder buffer = new StringBuilder();

                foreach (string element in Utils.ParseDistinguishedName(certificate.Subject))
                {
                    string key = element;
                    string value = String.Empty;

                    index = key.IndexOf('=');

                    if (index >= 0)
                    {
                        key = element.Substring(0, index);
                        value = element.Substring(index + 1);
                    }

                    if (key == "CN")
                    {
                        ApplicationNameTB.Text = value;
                    }

                    if (key == "O")
                    {
                        OrganizationTB.Text = value;
                    }

                    // work around to deal with invalid fields in some certificates.
                    if (key == "S")
                    {
                        key = "ST";
                    }

                    if (buffer.Length > 0)
                    {
                        buffer.Append('/');
                    }

                    buffer.Append(key);
                    buffer.Append('=');

                    if (value.IndexOf('/') != -1)
                    {
                        buffer.Append('"');
                        buffer.Append(value);
                        buffer.Append('"');
                    }
                    else
                    {
                        buffer.Append(value);
                    }
                }

                if (buffer.Length > 0)
                {
                    SubjectNameCK.Checked = true;
                    SubjectNameTB.Text = buffer.ToString();
                }

                string applicationUri = Utils.GetApplicationUriFromCertficate(certificate);

                if (!String.IsNullOrEmpty(applicationUri))
                {
                    ApplicationUriCK.Checked = true;
                    ApplicationUriTB.Text = applicationUri;
                }

                buffer = new StringBuilder();

                foreach (string domain in Utils.GetDomainsFromCertficate(certificate))
                {
                    if (buffer.Length > 0)
                    {
                        buffer.Append(',');
                    }

                    buffer.Append(domain);
                }

                if (buffer.Length > 0)
                {
                    DomainsCK.Checked = true;
                    DomainsTB.Text = buffer.ToString();
                }

                index = KeySizeCB.FindStringExact(certificate.PublicKey.Key.KeySize.ToString());

                if (index >= 0)
                {
                    KeySizeCB.SelectedIndex = index;
                }
            }
        }
        #endregion