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


C# StoreName.ToString方法代码示例

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


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

示例1: 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

示例2: 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

示例3: X509Store

		public X509Store (StoreName storeName, StoreLocation storeLocation)
		{
			if ((storeName < StoreName.AddressBook) || (storeName > StoreName.TrustedPublisher))
				throw new ArgumentException ("storeName");
			if ((storeLocation < StoreLocation.CurrentUser) || (storeLocation > StoreLocation.LocalMachine))
				throw new ArgumentException ("storeLocation");

			switch (storeName) {
			case StoreName.CertificateAuthority:
				_name = "CA";
				break;
			default:
				_name = storeName.ToString ();
				break;
			}
			_location = storeLocation;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:17,代码来源:X509Store.cs

示例4: 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

示例5: LoadCertificate

		public X509Certificate2 LoadCertificate(StoreName storeName, StoreLocation
		storeLocation, X509FindType findType, string value)
		{
			return LoadCertificate(storeName.ToString(), storeLocation, findType, value);
		}
开发者ID:polarnik,项目名称:Tools.CMSCreator,代码行数:5,代码来源:FormMain.cs

示例6: GetStore

 /// <summary>
 /// Helper function to connect to a cert store. Can be local or remote
 /// </summary>
 /// <param name="store">The store to look in</param>
 /// <param name="location">The location to look in</param>
 /// <param name="remoteComputer">remote computer to run on</param>
 /// <returns></returns>
 private static X509Store GetStore(StoreName store = StoreName.My, StoreLocation location = StoreLocation.LocalMachine, string remoteComputer = "")
 {
     var storeName = store.ToString();
     if (!ComputerManager.IsLocal(remoteComputer))
         storeName = @"\\" + remoteComputer + @"\" + store.ToString();
     return new X509Store(storeName, location);
 }
开发者ID:J4S0Nc,项目名称:Useful.Utilities,代码行数:14,代码来源:Certificate.cs

示例7: StoreNameToString

		// methods

		private static string StoreNameToString (StoreName sn) 
		{
			switch (sn) {
				case StoreName.CertificateAuthority:
					return "CA";
				default:
					return sn.ToString ();
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:11,代码来源:X509Store.cs

示例8: CertificateBinding

		public CertificateBinding(string certificateThumbprint, StoreName certificateStoreName, IPEndPoint ipPort, Guid appId, BindingOptions options = null)
			: this(certificateThumbprint, certificateStoreName.ToString(), ipPort, appId, options) { }
开发者ID:subTee,项目名称:SslCertBinding.Net,代码行数:2,代码来源:CertificateBinding.cs

示例9: ReadableStoreName

        private string ReadableStoreName(StoreName storeName)
        {
            string readable;

            switch (storeName)
            {
                case StoreName.My:
                    readable = "Personal Store";
                    break;
                case StoreName.AddressBook:
                    readable = "Other People Store";
                    break;
                default:
                    readable = storeName.ToString();
                    break;
            }

            return readable;
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:19,代码来源:X509CertificatePicker.cs

示例10: 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

示例11: BindCertificate

        public static void BindCertificate(IPEndPoint ipPort, byte[] hash, StoreName storeName, Guid appId)
        {
            if (ipPort == null) throw new ArgumentNullException("ipPort");
            if (hash == null) throw new ArgumentNullException("hash");

            CallHttpApi(
                delegate
                {
                    HTTP_SERVICE_CONFIG_SSL_SET configSslSet = new HTTP_SERVICE_CONFIG_SSL_SET();

                    GCHandle sockAddrHandle = CreateSockaddrStructure(ipPort);
                    IntPtr pIpPort = sockAddrHandle.AddrOfPinnedObject();
                    HTTP_SERVICE_CONFIG_SSL_KEY httpServiceConfigSslKey =
                        new HTTP_SERVICE_CONFIG_SSL_KEY(pIpPort);
                    HTTP_SERVICE_CONFIG_SSL_PARAM configSslParam = new HTTP_SERVICE_CONFIG_SSL_PARAM();

                    GCHandle handleHash = GCHandle.Alloc(hash, GCHandleType.Pinned);
                    configSslParam.AppId = appId;
                    configSslParam.DefaultCertCheckMode = 0;
                    configSslParam.DefaultFlags = 0; //HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT;
                    configSslParam.DefaultRevocationFreshnessTime = 0;
                    configSslParam.DefaultRevocationUrlRetrievalTimeout = 0;
                    configSslParam.pSslCertStoreName = storeName.ToString();
                    configSslParam.pSslHash = handleHash.AddrOfPinnedObject();
                    configSslParam.SslHashLength = hash.Length;
                    configSslSet.ParamDesc = configSslParam;
                    configSslSet.KeyDesc = httpServiceConfigSslKey;

                    IntPtr pInputConfigInfo =
                        Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_SSL_SET)));
                    Marshal.StructureToPtr(configSslSet, pInputConfigInfo, false);

                    try
                    {
                        uint retVal = HttpSetServiceConfiguration(IntPtr.Zero,
                                                                    HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
                                                                    pInputConfigInfo,
                                                                    Marshal.SizeOf(configSslSet),
                                                                    IntPtr.Zero);

                        if (ERROR_ALREADY_EXISTS != retVal)
                        {
                            ThrowWin32ExceptionIfError(retVal);
                        }
                        else
                        {
                            retVal = HttpDeleteServiceConfiguration(IntPtr.Zero,
                                                                    HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
                                                                    pInputConfigInfo,
                                                                    Marshal.SizeOf(configSslSet),
                                                                    IntPtr.Zero);
                            ThrowWin32ExceptionIfError(retVal);

                            retVal = HttpSetServiceConfiguration(IntPtr.Zero,
                                                                    HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo,
                                                                    pInputConfigInfo,
                                                                    Marshal.SizeOf(configSslSet),
                                                                    IntPtr.Zero);
                            ThrowWin32ExceptionIfError(retVal);
                        }
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(pInputConfigInfo);
                        if (handleHash.IsAllocated)
                            handleHash.Free();
                        if (sockAddrHandle.IsAllocated)
                            sockAddrHandle.Free();
                    }
                });
        }
开发者ID:joycelan,项目名称:trifleJS,代码行数:71,代码来源:HttpApi.cs


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