コード例 #1
0
        private static void AddEncryptingCertificate(Dictionary <string, string> result)
        {
            foreach (ServiceElement config in MicrosoftIdentityModelSection.Current.ServiceElements)
            {
                if (config.ServiceCertificate != null && config.ServiceCertificate.CertificateReference != null)
                {
                    var certificateInfo          = config.ServiceCertificate.CertificateReference;
                    X509Certificate2 certificate = CertificateUtility.GetCertificate(
                        certificateInfo.StoreName,
                        certificateInfo.StoreLocation,
                        certificateInfo.X509FindType,
                        certificateInfo.FindValue);

                    if (certificate != null)
                    {
                        StringBuilder rowHeader = new StringBuilder();
                        rowHeader.Append("Encrypting Certificate (from configuration)");
                        StringBuilder sb = new StringBuilder();
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Subject] {0}<br/>", certificate.Subject));
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Issuer] {0}<br/>", certificate.Issuer));
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Serial Number] {0}<br/>", certificate.SerialNumber));
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Not Before] {0}<br/>", certificate.NotBefore));
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Not After] {0}<br/>", certificate.NotAfter));
                        sb.Append(string.Format(CultureInfo.CurrentUICulture, "[Thumbprint] {0}<br/>", certificate.Thumbprint));

                        result[rowHeader.ToString()] = sb.ToString();
                    }
                }
            }
        }