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


C# X509Certificate.Sign方法代码示例

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


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

示例1: SelfSigned

		/// <summary>
		/// Factory method that creates a X509CertificateAuthority instance with
		/// an internal self signed certificate. This method allows creation without
		/// the need for the Configuration file, X509V3Extensions may be added
		/// with the X509V3ExtensionList parameter
		/// </summary>
		/// <param name="seq"></param>
		/// <param name="key"></param>
		/// <param name="digest"></param>
		/// <param name="subject"></param>
		/// <param name="start"></param>
		/// <param name="validity"></param>
		/// <param name="extensions"></param>
		/// <returns></returns>
		public static X509CertificateAuthority SelfSigned(
			ISequenceNumber seq,
			CryptoKey key,
			MessageDigest digest,
			X509Name subject,
			DateTime start,
			TimeSpan validity,
			IEnumerable<X509V3ExtensionValue> extensions)
		{
			var cert = new X509Certificate(
				           seq.Next(),
				           subject,
				           subject,
				           key,
				           start,
				           start + validity);

			if (extensions != null)
			{
				foreach (var extValue in extensions)
				{
					using (var ext = new X509Extension(cert, cert, extValue.Name, extValue.IsCritical, extValue.Value))
					{
						cert.AddExtension(ext);
					}
				}
			}

			cert.Sign(key, digest);

			return new X509CertificateAuthority(cert, key, seq);
		}
开发者ID:yaobos,项目名称:openssl-net,代码行数:46,代码来源:X509CertificateAuthority.cs

示例2: ProcessRequest

		/// <summary>
		/// Process an X509Request. This includes creating a new X509Certificate
		/// and signing this certificate with this CA's private key.
		/// </summary>
		/// <param name="request"></param>
		/// <param name="startTime"></param>
		/// <param name="endTime"></param>
		/// <param name="cfg"></param>
		/// <param name="section"></param>
		/// <param name="digest"></param>
		/// <returns></returns>
		public X509Certificate ProcessRequest(
			X509Request request,
			DateTime startTime,
			DateTime endTime,
			Configuration cfg,
			string section,
			MessageDigest digest)
		{
//			using (var pkey = request.PublicKey)
//			{
//				if (!request.Verify(pkey))
//					throw new Exception("Request signature validation failed");
//			}

			var cert = new X509Certificate(
				           serial.Next(),
				           request.Subject,
				           this.caCert.Subject,
				           request.PublicKey,
				           startTime,
				           endTime);

			if (cfg != null)
				cfg.ApplyExtensions(section, caCert, cert, request);

			cert.Sign(caKey, digest);

			return cert;
		}
开发者ID:yaobos,项目名称:openssl-net,代码行数:40,代码来源:X509CertificateAuthority.cs

示例3: CanVerify

		public void CanVerify()
		{
			DateTime start = DateTime.Now;
			DateTime end = start + TimeSpan.FromMinutes(10);
			CryptoKey key = new CryptoKey(new DSA(true));
			using (X509Certificate cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end)) {
				cert.Sign(key, MessageDigest.DSS1);
				Assert.AreEqual(true, cert.Verify(key));

				CryptoKey other = new CryptoKey(new DSA(true));
				Assert.AreEqual(false, cert.Verify(other));
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:13,代码来源:TestX509Certificate.cs

示例4: CanSign

		public void CanSign()
		{
			DateTime start = DateTime.Now;
			DateTime end = start + TimeSpan.FromMinutes(10);
			CryptoKey key = new CryptoKey(new DSA(true));
			using (X509Certificate cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end)) {
				cert.Sign(key, MessageDigest.DSS1);
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:9,代码来源:TestX509Certificate.cs

示例5: ProcessRequest

        /// <summary>
        /// Process and X509Request. This includes creating a new X509Certificate
        /// and signing this certificate with this CA's private key.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="digest"></param>
        /// <returns></returns>
        public X509Certificate ProcessRequest(X509Request request, DateTime startTime, DateTime endTime, MessageDigest digest)
        {
            //using (CryptoKey pkey = request.PublicKey)
            //{
            //    if (!request.Verify(pkey))
            //        throw new Exception("Request signature validation failed");
            //}

            X509Certificate cert = new X509Certificate(
                serial.Next(),
                request.Subject,
                this.caCert.Subject,
                request.PublicKey,
                startTime,
                endTime);

            if (this.cfg != null)
                this.cfg.ApplyExtensions("v3_ca", this.caCert, cert, request);

            cert.Sign(this.caKey, digest);

            return cert;
		}
开发者ID:Nangal,项目名称:http2-katana,代码行数:32,代码来源:X509CertificateAuthority.cs

示例6: SelfSigned

        /// <summary>
        /// Factory method that creates a X509CertificateAuthority instance with
        /// an internal self signed certificate. This method allows creation without
        /// the need for the Configuration file, X509V3Extensions may be added
        /// with the X509V3ExtensionList parameter
        /// </summary>
        /// <param name="seq"></param>
        /// <param name="key"></param>
        /// <param name="digest"></param>
        /// <param name="subject"></param>
        /// <param name="start"></param>
        /// <param name="validity"></param>
        /// <param name="extensions"></param>
        /// <returns></returns>
        public static X509CertificateAuthority SelfSigned(
            ISequenceNumber seq,
            CryptoKey key,
            MessageDigest digest,
            X509Name subject,
            DateTime start,
            TimeSpan validity,
            X509V3ExtensionList extensions)
        {
            X509Certificate cert = new X509Certificate(
                seq.Next(),
                subject,
                subject,
                key,
                start,
                start + validity);

            if (null != extensions)
            {
                foreach (X509V3ExtensionValue extValue in extensions)
                {
                    X509Extension ext = new X509Extension(cert, cert, extValue.Name, extValue.IsCritical, extValue.Value);
                    cert.AddExtension(ext);
                }
            }

            cert.Sign(key, digest);

            return new X509CertificateAuthority(cert, key, seq, null);
		}
开发者ID:Nangal,项目名称:http2-katana,代码行数:44,代码来源:X509CertificateAuthority.cs

示例7: MakeRoot

		private static Authority MakeRoot()
		{
			DSA dsa = new DSA(new DSAParameters(512));
			CryptoKey key = new CryptoKey(dsa);
			X509Name subject = new X509Name("CN=.");
			X509Certificate cert = new X509Certificate(
				0,
				subject,
				subject,
				key,
				TimeSpan.FromDays(365));
			cert.Sign(key, MessageDigest.DSS1);

			return new Authority(cert, key);
		}
开发者ID:kengmail,项目名称:OpenSSL.NET,代码行数:15,代码来源:Program2.cs


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