コード例 #1
0
        private static X509Certificate2 LoadFromStoreCert(CertificateConfig certInfo)
        {
            var subject       = certInfo.Subject;
            var storeName     = certInfo.Store;
            var location      = certInfo.Location;
            var storeLocation = StoreLocation.CurrentUser;

            if (!string.IsNullOrEmpty(location))
            {
                storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), location, ignoreCase: true);
            }
            var allowInvalid = certInfo.AllowInvalid ?? false;

            return(CertificateLoader.LoadFromStoreCert(subject, storeName, storeLocation, allowInvalid));
        }
コード例 #2
0
 private X509Certificate2 LoadCertificate(CertificateConfig certInfo, string endpointName)
 {
     if (certInfo.IsFileCert && certInfo.IsStoreCert)
     {
         throw new InvalidOperationException(ReplicaCoreStrings.FormatMultipleCertificateSources(endpointName));
     }
     else if (certInfo.IsFileCert)
     {
         var env = Options.ApplicationServices.GetRequiredService <IHostingEnvironment>();
         return(new X509Certificate2(Path.Combine(env.ContentRootPath, certInfo.Path), certInfo.Password));
     }
     else if (certInfo.IsStoreCert)
     {
         return(LoadFromStoreCert(certInfo));
     }
     return(null);
 }