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


C# X509Certificate.ToString方法代码示例

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


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

示例1: ValidateCertAgainstBaseline

    static bool ValidateCertAgainstBaseline(IDictionary<string, string> certVals, X509Certificate cer)
    {

        bool retVal = true;
        long effectiveDateFound, expiryDateFound, effectiveDateBsl, expiryDateBsl;
        byte[] bytes;
        string str;
        int    hash;
        IntPtr handle;
        // now validate against the actual cert

        if (!certVals["HashString"].Equals(cer.GetCertHashString()))
        {
            TestFramework.LogError("001", "Expected hash string: " + certVals["HashString"] + ", found: " + cer.GetCertHashString());
            retVal = false;
        }

	// check the dates
	try
	{
            effectiveDateBsl   = Convert.ToInt64(certVals["EffectiveDateStringInTicks"]);
            effectiveDateFound = DateTime.Parse(cer.GetEffectiveDateString(), CultureInfo.InvariantCulture).ToUniversalTime().Ticks;
            expiryDateBsl      = Convert.ToInt64(certVals["ExpirationDateStringInTicks"]);
            expiryDateFound    = DateTime.Parse(cer.GetExpirationDateString(), CultureInfo.InvariantCulture).ToUniversalTime().Ticks;

            if (effectiveDateBsl != effectiveDateFound)
            {
                TestFramework.LogError("002", "Expected \"Valid From\": [" + (new DateTime(effectiveDateBsl, DateTimeKind.Utc)).ToString() + "], found: [" + cer.GetEffectiveDateString() +" nonUTC]");
                TestFramework.LogError("002", "                       ticks(" + effectiveDateBsl + ") found ticks(" + effectiveDateFound + ")");
                retVal = false;
            }

            if (expiryDateBsl != expiryDateFound)
            {
                TestFramework.LogError("003", "Expected \"Valid To\": [" + (new DateTime(expiryDateBsl)).ToString() + "], found: [" + cer.GetExpirationDateString() + " nonUTC]");
                TestFramework.LogError("003", "                       ticks(" + expiryDateBsl + ") found ticks(" + expiryDateFound + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestFramework.LogError("103", "Unexpected exception: " + e);
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: Format");
        if (!certVals["Format"].Equals(cer.GetFormat()))
        {
            TestFramework.LogError("004", "Expected format: " + certVals["Format"] + ", found: " + cer.GetFormat());
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: Issuer");
        if (!certVals["Issuer"].Equals(cer.Issuer))
        {
            TestFramework.LogError("005", "Expected issuer: " + certVals["Issuer"] + ", found: " + cer.Issuer);
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: KeyAlgorithm");
        if (!certVals["KeyAlgorithm"].Equals(cer.GetKeyAlgorithm()))
        {
            TestFramework.LogError("006", "Expected key algorithm: " + certVals["KeyAlgorithm"] + ", found: " + cer.GetKeyAlgorithm());
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: KeyAlgorithmParameters");
        if (!certVals["KeyAlgorithmParameters"].Equals(cer.GetKeyAlgorithmParametersString()))
        {
            TestFramework.LogError("007", "Expected key alg parameters :" + certVals["KeyAlgorithmParameters"] + ", found :" +
                    cer.GetKeyAlgorithmParametersString());
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: PublicKeyString");
        if (!certVals["PublicKeyString"].Equals(cer.GetPublicKeyString()))
        {
            TestFramework.LogError("008", "Expected public key: " + certVals["PublicKeyString"] + ", found: " +
                cer.GetPublicKeyString());
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: SerialNumberString");
        if (!certVals["SerialNumberString"].Equals(cer.GetSerialNumberString()))
        {
            TestFramework.LogError("009", "Expected serial number: " + certVals["SerialNumberString"] + ", found: " + cer.GetSerialNumberString());
            retVal = false;
        }

        TestFramework.LogInformation("  Validating field: Subject");
        if (!certVals["Subject"].Equals(cer.Subject))
        {
            TestFramework.LogError("010", "Expected subject: " + certVals["Subject"] + ", found: " + cer.Subject);
            retVal = false;
        }

        TestFramework.LogInformation("  Retrieving field: CertHash");
        bytes = cer.GetCertHash();

        TestFramework.LogInformation("  Retrieving field: HashCode");
//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:X509CertificateRunSuite.cs

示例2: X509CertEmptyToString

 public static void X509CertEmptyToString()
 {
     using (var c = new X509Certificate())
     {
         string expectedResult = "System.Security.Cryptography.X509Certificates.X509Certificate";
         Assert.Equal(expectedResult, c.ToString());
         Assert.Equal(expectedResult, c.ToString(false));
         Assert.Equal(expectedResult, c.ToString(true));
     }
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:CertTests.cs

示例3: CertificateValidation

	static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors)
	{
		Console.WriteLine ("CertificateValidation");
		Console.WriteLine (certificate.ToString (true));
		Console.WriteLine ("\tError(s)");
		foreach (int error in certificateErrors)
			Console.WriteLine ("\t\t#{0}", error);
		Console.WriteLine ();
		return true;
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:10,代码来源:mutual.cs

示例4: CertificateValidation

	static bool CertificateValidation (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors certificateErrors)
	{
		Console.WriteLine ("CertificateValidation");
		Console.WriteLine (certificate.ToString (true));
		Console.WriteLine ("Chain");
		Console.WriteLine (chain);
		Console.WriteLine ("\tError(s)");
		Console.WriteLine (certificateErrors);
		Console.WriteLine ();
		return true;
	}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:mutual.cs

示例5: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate.ToString (true));
		Console.WriteLine ();
		return clientCertificates [0];
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:13,代码来源:mutual.cs

示例6: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (object sender, string targetHost, X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string [] acceptableIssuers)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate != null ? serverCertificate.ToString (true) : null);
		Console.WriteLine ();
		if (i == 1)
			return null;
		X509Certificate2 cc = new X509Certificate2 (clientCertificates [0]);
		cc.PrivateKey = PrivateKeySelection (cc, targetHost);
		return cc;
	}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:mutual.cs

示例7: CheckValidationResult

		public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error)
		{
			if (error != 0) {
				Console.WriteLine (certificate.ToString (true));
				// X509Certificate.ToString(true) doesn't show dates :-(
				Console.WriteLine ("\tValid From:  {0}", certificate.GetEffectiveDateString ());
				Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine);

				ShowCertificateError (error);
			}
			// whatever the reason we do not stop the SSL connection
			return true;
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:13,代码来源:postecho.cs

示例8: CertificateValidation

	private static bool CertificateValidation (X509Certificate certificate, int[] certificateErrors)
	{
		if (certificateErrors.Length > 0)
		{
			Console.WriteLine (certificate.ToString (true));
			// X509Certificate.ToString(true) doesn't show dates :-(
			Console.WriteLine ("\tValid From:  {0}", certificate.GetEffectiveDateString ());
			Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine);
			// multiple errors are possible using SslClientStream
			foreach (int error in certificateErrors)
			{
				ShowCertificateError (error);
			}
		}
		// whatever the reason we do not stop the SSL connection
		return true;
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:17,代码来源:postecho.cs

示例9: PrivateKeySelection

	static AsymmetricAlgorithm PrivateKeySelection (X509Certificate certificate, string targetHost)
	{
		Console.WriteLine ("PrivateKeySelection");
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.WriteLine (certificate.ToString (true));
		Console.WriteLine ("\tPrivateKeySelection ({0})", p12.Keys.Count);
		Console.WriteLine ();
		return (AsymmetricAlgorithm) p12.Keys [0];
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:9,代码来源:mutual.cs

示例10: CanGetAsPEM

		public void CanGetAsPEM()
		{
			string data = LoadString(Resources.CaCrt);
			using (BIO bio = new BIO(data)) {
				string expected = data.Replace("\r\n", "\n");
				using (X509Certificate cert = new X509Certificate(bio)) {
					string pem = cert.PEM;
					string text = cert.ToString();

					Assert.AreEqual(expected, text + pem);
				}
			}
		}
开发者ID:challal,项目名称:scallion,代码行数:13,代码来源:TestX509Certificate.cs

示例11: iOSAPNS

        /*
        public string iOSAPNS(String DeviceTokenlistString, String content)
        {

            APNSSender test = new APNSSender();

            return test.SendAPNS(DeviceTokenlistString, content);
        }
         */


        /// <summary>  
        ///  傳入 DeviceToken  與 要傳的訊息
        /// </summary>  
        /// 手機上方 最多五則
        /// 警報日期:2015/03/04 11:55:00 \n類型/嚴重度:超速 / [嚴重]\n名稱:連續超速70km  3分鐘\n車號/駕駛人:kw-car03 / 易大師
        /// APNS 限制 payload 256bytes 超過就不發了 不过由于aps,alert等会占用部分长度,所以一般剩余140-200之间。
        /// 實測560個字都傳的出去 只是手機顯示最多4行而已
        /// <param name="inDeviceToken ID"> 手機端 Registration ID</param>  
        /// <param name="inMessage">訊息內容</param>  
        public String SendAPNS(String inDeviceToken, String inMessage)
        {
            //http://blog.sina.com.cn/s/blog_6f9a9718010128hi.html
            //太連續用單一個發送 會被蘋果認為是 dos 攻擊 而中斷連線   用單一個多次發送 遇到錯誤的token會中斷發送 接下來的都會無法發送
            System.Threading.Thread.Sleep(50);

        //    str = "{\"aps\":{\"alert\":\"" + s2 + "\",\"badge\":10,\"sound\":\"default\"}}";
            // badge 設為 0 就不會出現數字
            mAPNSMessage = "{\"aps\":{\"alert\":\"" + inMessage + "\",\"badge\":0,\"sound\":\"default\"}}";
          
            int port = 2195;
       //     string certificatepath = ConfigurationManager.AppSettings["p12FilePath"];
       //     string certificatepath = "D:\\VisualStudioProject\\Fleet\\new_aps_developer.p12";
            //string certificatepath = "D:\\VisualStudioProject\\Fleet\\distribution_aps_developer.p12";
        //    string certificatepath = "D:\\VisualStudioProject\\Fleet\\fleetivity_aps_developer.p12";
         //   string certificatepath = "C:\\inetpub\\DotNetNuke\\fleetivity_aps_developer.p12";

            string certificatepath = HttpContext.Current.Server.MapPath("/") + "certificate\\fleetivity_aps_developer.p12";

            

            string password = "abc123";

            // Apple development server address
            string hostIP = "gateway.sandbox.push.apple.com";//

           

            string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, certificatepath);
            certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12Filename), password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
            certificates = new X509CertificateCollection();
            certificates.Add(certificate);

            if (certificate.ToString().Contains("Production"))
            {
                hostIP = "gateway.push.apple.com";
            }
            else
            {
                hostIP = "gateway.sandbox.push.apple.com";
            }

            TcpClient apnsClient = new TcpClient();
            apnsClient.Connect(hostIP, port);
            SslStream apnsStream = new SslStream(apnsClient.GetStream(), false, new RemoteCertificateValidationCallback(validateServerCertificate), new LocalCertificateSelectionCallback(selectLocalCertificate));
            try
            {
                apnsStream.AuthenticateAsClient(hostIP, certificates, System.Security.Authentication.SslProtocols.Tls, false);
            }
            catch (System.Security.Authentication.AuthenticationException ex)
            {
                Console.WriteLine("error:" + ex.Message);
            }

            if (!apnsStream.IsMutuallyAuthenticated)
            {
                Console.WriteLine("error:" + "Ssl Stream Failed to Authenticate");
            }

            if (!apnsStream.CanWrite)
            {
                Console.WriteLine("error:" + "Ssl Stream is not Writable");
            }
            Byte[] message = ToBytes(inDeviceToken);
            apnsStream.Write(message);
            return System.Text.Encoding.UTF8.GetString(message);
        }
开发者ID:asaki0510,项目名称:AlarmRuleSet,代码行数:87,代码来源:APNSSender.cs

示例12: CanGetAsPEM

		public void CanGetAsPEM()
		{
			var data = Util.LoadString(Resources.CaCrt);
			var expected = data.Replace("\r\n", "\n");
			using (var bio = new BIO(data))
			using (var cert = new X509Certificate(bio))
			{
				var pem = cert.PEM;
				var text = cert.ToString();

				Assert.AreEqual(expected, text + pem);
			}
		}
开发者ID:yaobos,项目名称:openssl-net,代码行数:13,代码来源:TestX509Certificate.cs

示例13: CanGetAsPEM

		public void CanGetAsPEM()
		{
			using (BIO bio = BIO.File(Paths.CaCrt, "r"))
			{
				string expected = File.ReadAllText(Paths.CaCrt).Replace("\r\n", "\n");
				using (X509Certificate cert = new X509Certificate(bio))
				{
					string pem = cert.PEM;
					string text = cert.ToString();

					Assert.AreEqual(expected, text + pem);
				}
			}
		}
开发者ID:kengmail,项目名称:OpenSSL.NET,代码行数:14,代码来源:X509CertificateTest.cs


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