当前位置: 首页>>代码示例>>C#>>正文


C# StoreLocation.ToString方法代码示例

本文整理汇总了C#中StoreLocation.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# StoreLocation.ToString方法的具体用法?C# StoreLocation.ToString怎么用?C# StoreLocation.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StoreLocation的用法示例。


在下文中一共展示了StoreLocation.ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCertificateByThumbprint

        public X509Certificate2 GetCertificateByThumbprint(StoreLocation storeLocation, string thumbprint)
        {
            X509Store certStore = new X509Store(StoreName.My, storeLocation);
            try
            {
                try
                {
                    certStore.Open(OpenFlags.ReadOnly);
                }
                catch (Exception ex)
                {
                    var outerEx = new SecurityException(string.Format("Failed to open X509Store in '{0}'.", storeLocation.ToString()), ex);
                    throw outerEx;
                }
                

                foreach(var thisCert in certStore.Certificates)
                {
                    Console.WriteLine(thisCert.Thumbprint + "\t" + thisCert.Subject);
                }

                var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
                if (certCollection == null || certCollection.Count == 0)
                {
                    throw new ArgumentException(string.Format("thumbprint '{0}' does not match any certificates in '{1}'.", thumbprint, storeLocation.ToString()));
                }
                var cert = certCollection[0];
                return cert;
            }
            finally
            {
                certStore.Close();
            }
        }
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:34,代码来源:_baseTest.cs

示例2: AddCertificate

        /// <summary>
        /// Adds a certificate to a cert store in the local machine.
        /// </summary>
        /// <param name="certificate">The file path to find the certificate file.</param>
        /// <param name="storeName">Name of the certificate store.</param>
        /// <param name="storeLocation">Location of the certificate store.</param>
        public static void AddCertificate(X509Certificate2 certificate, StoreName storeName, StoreLocation storeLocation)
        {
            X509Store store = null;

            try
            {
                store = new X509Store(storeName, storeLocation);
                store.Open(OpenFlags.ReadOnly | OpenFlags.ReadWrite);

                var certificates = from cert in store.Certificates.OfType<X509Certificate2>()
                                   where cert.Thumbprint == certificate.Thumbprint
                                   select cert;

                if (certificates.FirstOrDefault() == null)
                {
                    store.Add(certificate);
                    Console.WriteLine(string.Format("Added certificate with thumbprint {0} to store '{1}', has private key: {2}.", certificate.Thumbprint, storeName.ToString(), certificate.HasPrivateKey));

                    store.Close();
                    store = null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("AddCert exception storeName={0} storeLocation={1}", storeName.ToString(), storeLocation.ToString()), ex);
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }
        }
开发者ID:hendryluk,项目名称:twitterbigdata,代码行数:40,代码来源:CertificateHelper.cs

示例3: FindCert

        private NuGetCertificate FindCert(CertificatesHub certs, StoreLocation storeLocation)
        {
            var specificMatch = certs.GetCertificateFromConfigSetting(ConfigSetting, StoreName.My, storeLocation);
            if(specificMatch != null) 
            {
                AzureHubEventSource.Log.SingleMatch(storeLocation.ToString(), specificMatch.Thumbprint, specificMatch.Subject);
                return specificMatch;
            }

            var candidates = certs
                .GetCertificatesByPurpose(CommonCertificatePurposes.AzureManagement, StoreName.My, storeLocation)
                .ToList();
            // No candidates? Return null.
            if (candidates.Count == 0)
            {
                AzureHubEventSource.Log.NoMatch(storeLocation.ToString());
                return null;
            }
            // One candidate? Return it.
            else if (candidates.Count == 1)
            {
                AzureHubEventSource.Log.SingleMatch(storeLocation.ToString(), candidates[0].Thumbprint, candidates[0].Subject);
                return candidates[0];
            }
            // Multiple candidates? Return the first one
            else
            {
                var match = candidates.FirstOrDefault();
                AzureHubEventSource.Log.MultipleMatches(storeLocation.ToString(), match.Thumbprint, match.Subject);
                return match;
            }
        }
开发者ID:stephenosrajan,项目名称:NuGet.Services.Platform,代码行数:32,代码来源:AzureHub.cs

示例4: X509CertificatePickerView

 /// <summary>
 /// Initializes a new instance of the <see cref="T:X509CertificatePickerView"/> class.
 /// </summary>
 /// <param name="storeLocation">The store location.</param>
 /// <param name="storeName">Name of the store.</param>
 public X509CertificatePickerView(StoreLocation storeLocation, StoreName storeName)
     : this()
 {
     this.storeLocation = storeLocation;
     this.storeName = storeName;
     cbLocation.SelectedItem = storeLocation.ToString();
     cbStore.SelectedItem = storeName.ToString();
 }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:13,代码来源:X509CertificatePickerView.cs

示例5: FromStoreLocation

 public static CertificateStoreLocation FromStoreLocation(StoreLocation location)
 {
     return new CertificateStoreLocation(
         new SystemStoreLocationInfo()
         {
             Flags = (uint)location << 16,
             Name = location.ToString()
         });
 }
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:9,代码来源:CertificateStoreLocation.cs

示例6: Attribute

        public ExpectedJwtSecurityTokenRequirement
        (
            uint? tokenSize = null, Int32? clock = null, uint? life = null, X509CertificateValidator cert = null, string name = JwtConstants.ReservedClaims.Sub, string role = null, X509RevocationMode? revMode = null, X509CertificateValidationMode? certMode = null, StoreLocation? storeLoc = null, ExpectedException expectedException = null,
            string handler = JwtSecurityTokenHandlerType, string requirement = Elements.JwtSecurityTokenRequirement,
            string attributeEx1 = "", string attributeEx2 = "", string attributeEx3 = "", string attributeEx4 = "",
            string elementEx1 = comment, string elementEx2 = comment, string elementEx3 = comment, string elementEx4 = comment, string elementEx5 = comment, string elementEx6 = comment,
            string elementClose = closeRequirement

        )
        {
            MaxTokenSizeInBytes = tokenSize;
            NameClaimType = name;
            RoleClaimType = role;
            CertValidator = cert;
            ClockSkewInSeconds = clock;
            DefaultTokenLifetimeInMinutes = life;
            CertRevocationMode = revMode;
            CertValidationMode = certMode;
            CertStoreLocation = storeLoc;
            ExpectedException = expectedException ?? ExpectedException.NoExceptionExpected;
            string[] sParams = 
            {
                handler,
                requirement,
                CertRevocationMode == null ? string.Empty : Attribute( Attributes.RevocationMode, CertRevocationMode.Value.ToString() ),
                attributeEx1,
                CertValidationMode == null ? string.Empty : Attribute( Attributes.ValidationMode, CertValidationMode.Value.ToString() ),
                attributeEx2,
                CertValidator == null ? string.Empty : Attribute( Attributes.Validator, CertValidator.GetType().ToString() +", System.IdentityModel.Tokens.Jwt.Tests" ),
                attributeEx3,
                CertStoreLocation == null ? string.Empty : Attribute( Attributes.TrustedStoreLocation, CertStoreLocation.ToString() ),
                attributeEx4,
                elementEx1,
                ClockSkewInSeconds == null ? string.Empty : ElementValue( Elements.MaxClockSkewInMinutes, ClockSkewInSeconds.Value.ToString() ),
                elementEx2,
                MaxTokenSizeInBytes == null ? string.Empty : ElementValue( Elements.MaxTokenSizeInBytes, MaxTokenSizeInBytes.Value.ToString() ),
                elementEx3,
                DefaultTokenLifetimeInMinutes == null ? string.Empty : ElementValue( Elements.DefaultTokenLifetimeInMinutes, DefaultTokenLifetimeInMinutes.Value.ToString() ),
                elementEx4,
                NameClaimType == null ? string.Empty : ElementValue( Elements.NameClaimType, NameClaimType ),
                elementEx5,
                RoleClaimType == null ? string.Empty : ElementValue( Elements.RoleClaimType, RoleClaimType ),
                elementEx6,
                elementClose,
            };
            Config = string.Format(ElementTemplate, sParams);
        }
开发者ID:richardschneider,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:47,代码来源:JwtConfigTests.cs

示例7: RemoveCertificate

        /// <summary>
        /// Removes a certificate from a cert store in the local machine.
        /// </summary>
        /// <param name="certName">The name of the certificate file to remove.</param>
        /// <param name="storeName">Name of the certificate store.</param>
        /// <param name="storeLocation">Location of the certificate store.</param>
        public static void RemoveCertificate(string certName, StoreName storeName, StoreLocation storeLocation)
        {
            X509Store store = null;

            string certIssuerName = string.Format("CN={0}, OU=streaminsight, O=microsoft, C=us", certName);

            try
            {
                store = new X509Store(storeName, storeLocation);
                store.Open(OpenFlags.ReadOnly | OpenFlags.ReadWrite);
                var allCertificates = from cert in store.Certificates.OfType<X509Certificate2>()
                                      where cert.Issuer.Equals(certIssuerName)
                                      select cert;

                foreach (X509Certificate2 cert in allCertificates)
                {
                    store.Remove(cert);
                    Console.WriteLine(string.Format("Removed certificate with thumbprint {0} from store '{1}', has private key: {2}.", cert.Thumbprint, storeName.ToString(), cert.HasPrivateKey));
                }

                store.Close();
                store = null;
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Remove certificate hit exception, storeName={0} storeLocation={1}.", storeName.ToString(), storeLocation.ToString()), ex);
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }
        }
开发者ID:hendryluk,项目名称:twitterbigdata,代码行数:41,代码来源:CertificateHelper.cs

示例8: GetApplicationCertificateFromStore

        internal X509Certificate2 GetApplicationCertificateFromStore(
            Guid applicationId,
            StoreLocation storeLocation,
            string certSubject)
        {
            if (certSubject == null)
            {
                certSubject = "CN=" + GetApplicationCertificateSubject(applicationId);
            }

            HealthVaultPlatformTrace.LogCertLoading(
                "Opening cert store (read-only): {0}",
                storeLocation.ToString());

            RSACryptoServiceProvider rsaProvider = null;
            string thumbprint = null;

            X509Certificate2 result = null;
            X509Store store = new X509Store(storeLocation);

            store.Open(OpenFlags.ReadOnly);

            try
            {
                HealthVaultPlatformTrace.LogCertLoading(
                    "Looking for matching cert with subject: {0}",
                    certSubject);

                foreach (X509Certificate2 cert in store.Certificates)
                {
                    if (String.Equals(
                            cert.Subject,
                            certSubject,
                            StringComparison.OrdinalIgnoreCase))
                    {
                        HealthVaultPlatformTrace.LogCertLoading(
                            "Found matching cert subject with thumbprint: {0}",
                            cert.Thumbprint);

                        thumbprint = cert.Thumbprint;

                        HealthVaultPlatformTrace.LogCertLoading("Looking for private key");
                        rsaProvider = (RSACryptoServiceProvider)cert.PrivateKey;
                        HealthVaultPlatformTrace.LogCertLoading("Private key found");

                        result = cert;
                        break;
                    }
                }
            }
            catch (CryptographicException e)
            {
                HealthVaultPlatformTrace.LogCertLoading(
                    "Failed to retrieve private key for certificate: {0}",
                    e.ToString());
            }
            finally
            {
                store.Close();
            }

            if (rsaProvider == null || String.IsNullOrEmpty(thumbprint))
            {
                throw new SecurityException(
                        ResourceRetriever.FormatResourceString(
                            "CertificateNotFound",
                            certSubject,
                            storeLocation));
            }

            return result;
        }
开发者ID:marteaga,项目名称:healthvault-azurestorage,代码行数:72,代码来源:HealthApplicationConfiguration.cs

示例9: Print

	static X509Certificate2Collection Print(StoreLocation loc)
		{
		Console.WriteLine( String.Empty ) ; 
		Console.WriteLine( "Certificates returned from: " + loc.ToString() + "\\" + storeName ) ; 
		X509Store store = new X509Store( storeName , loc) ; 
		store.Open( OpenFlags.ReadOnly ) ;		
		X509Certificate2Collection certs = store.Certificates ; 
		foreach( X509Certificate2 cert in certs ) 
			{
			Console.WriteLine( cert.Thumbprint ) ; 
			}
		store.Close() ; 		
		return certs ; 
		}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:14,代码来源:storebug.cs

示例10: Compare

	static bool Compare( StoreLocation loc , X509Certificate2Collection certs ) 
		{
		bool res = true ; 
		string regPath = "Software\\Microsoft\\SystemCertificates\\" + storeName + "\\Certificates" ; 
		Console.WriteLine( String.Empty ) ; 
		Console.WriteLine( "Certificates found in: " + loc.ToString() + "\\" + regPath ) ; 
		RegistryKey keyLocation = loc == StoreLocation.CurrentUser ? Registry.CurrentUser : Registry.LocalMachine ; 
		RegistryKey rk = keyLocation.OpenSubKey( regPath , true ) ; 
		string[] subKeys = rk.GetSubKeyNames() ; 

		for( int i = 0 ; i < subKeys.Length ; i++ ) 
			{
			Console.WriteLine( subKeys[i] ) ; 
			
			//Now make sure each subkey name exists in certs
			if( certs.Find( X509FindType.FindByThumbprint , subKeys[i] , false ).Count == 0 )
				res = false ; 
			else
				res &= true ; 
			}
		rk.Close() ; 
		return res ; 
		}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:23,代码来源:storebug.cs

示例11: CreateCertificate

        public X509Certificate2 CreateCertificate(
            StoreLocation storeLocation,
            string storeName,
            string applicationName,
            string applicationUri,
            IList<string> hostNames,
            string organization,
            ushort keySize,
            ushort lifetimeInYears)
        {
            X509Certificate2 certificate = CreateCertificate(
                CertificateStoreType.Windows,
                storeLocation.ToString() + "\\" + storeName,
                applicationUri,
                applicationName,
                null,
                hostNames,
                keySize,
                (ushort)(lifetimeInYears * 12));

            return certificate;
        }
开发者ID:OPCFoundation,项目名称:Misc-Tools,代码行数:22,代码来源:CertificateFactory.cs

示例12: GetCertificate

        /// <summary>
        /// Searches for a certificate in certificate store and returns the matching certificate
        /// </summary>
        /// <param name="storeLocation">Store Location: This can be one of LocalMachine or UserName</param>
        /// <param name="storeName">Store Location: Currently this can only be My store.</param>
        /// <param name="thumbprint">Certificate thumbprint</param>
        /// <returns>Matching certificate</returns>
        private X509Certificate2 GetCertificate(StoreLocation storeLocation, StoreName storeName, string masterKeyPath, string thumbprint, bool isSystemOp)
        {
            // Open specified certificate store
            X509Store certificateStore = null;

            try
            {
                certificateStore = new X509Store(storeName, storeLocation);
                certificateStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                // Search for the specified certificate
                X509Certificate2Collection matchingCertificates =
                            certificateStore.Certificates.Find(X509FindType.FindByThumbprint,
                            thumbprint,
                            false);

                // Throw an exception if a cert with the specified thumbprint is not found
                if (matchingCertificates == null || matchingCertificates.Count == 0)
                {
                    throw SQL.CertificateNotFound(thumbprint, storeName.ToString(), storeLocation.ToString(), isSystemOp);
                }

                X509Certificate2 certificate = matchingCertificates[0];
                if (!certificate.HasPrivateKey)
                { 
                    // ensure the certificate has private key
                    throw SQL.CertificateWithNoPrivateKey(masterKeyPath, isSystemOp);
                }

                // return the matching certificate
                return certificate;
            }
            finally
            {
                // Close the certificate store
                if (certificateStore != null)
                {
                    certificateStore.Close();
                }
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:48,代码来源:SqlColumnEncryptionCertificateStoreProvider.cs


注:本文中的StoreLocation.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。