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


C# X509Certificate2.ToString方法代码示例

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


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

示例1: X509Cert2EmptyToString

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

示例2: Matches

	//
	//	Returns true is all available data in CertificateInfo matches the corresponding data in X509Certificate2 object
	//
	public bool Matches(X509Certificate2 cert)
	{
		bool bRes = true;
		
		if (PrivateKeyFile != null)
		{
			// TODO: implement
		}

		// get the public key
		PublicKey pk = cert.PublicKey;

		// compare the algorithm if available
		if ( !CompareStrings( pk.Oid.Value , PublicKeyAlg ) )
		{
			Log.Comment("Public key algorithm mismatch (1): " + pk.Oid.Value + " != " + PublicKeyAlg);
			bRes = false;
		}
		if ( !CompareStrings( cert.GetKeyAlgorithm() , PublicKeyAlg) )
		{
			Log.Comment("Public key algorithm mismatch (2): " + cert.GetKeyAlgorithm() + " != " + PublicKeyAlg);
			bRes = false;
		}

		// compare the public key blob
		if (PublicKeyBlob != null)
			if (!XmlDriver.Compare(pk.EncodedKeyValue.RawData, PublicKeyBlob)) 
			{
				Log.Comment("Public key blob mismatch: " + "\n" +
								BitConverter.ToString(pk.EncodedKeyValue.RawData) + " != " +
								BitConverter.ToString(PublicKeyBlob));
				bRes = false;								
			}

		// compare the private key
		// TODO: enhance, compare the actual value
		// The idea for now is that if there is a password that means there is a private key
		if (Password != null)
		{
			if (cert.PrivateKey == null)
			{
				Log.Comment("BAD: PrivateKey is null");
				bRes = false;
			} else
			{
				Log.Comment("Private Key is there - " + cert.PrivateKey);
			}
		}
		

		// compare the version
		if (Version != -1)
			if (cert.Version != Version)
			{
				Log.Comment("Version mismatch: " + cert.Version + " != " + Version);
				bRes = false;
			}

		// compare the subject
		if (Subject != null)
			if ( !CompareStrings( cert.SubjectName.Name , Subject) )
			{
				Log.Comment("Subject mismatch: " + cert.SubjectName.Name + " != " + Subject);
				bRes = false;
			}

		// compare the Issuer
		if (Issuer != null)
			if ( !CompareStrings( cert.IssuerName.Name , Issuer) )
			{
				Log.Comment("Issuer mismatch: " + cert.IssuerName.Name + " != " + Issuer);
				bRes = false;
			}

		// compare the serial number
		if (SerialNumber != null) 
			if ( !CompareStrings( cert.SerialNumber , SerialNumber) )
			{
				Log.Comment("Serial number mismatch: " + cert.SerialNumber + " != " + SerialNumber);
				bRes = false;
			}

		// compare the NotBefore
		if (NotBefore != DateTime.MinValue)
			if (cert.NotBefore.CompareTo(NotBefore) != 0)
			{
				Log.Comment("NotBefore mismatch: " + cert.NotBefore + " != " + NotBefore);
				bRes = false;
			}

		// compare the NotAfter				
		if (NotAfter != DateTime.MinValue)
			if (cert.NotAfter.CompareTo(NotAfter) != 0)
			{
				Log.Comment("NotAfter mismatch: " + cert.NotAfter + " != " + NotAfter);
				bRes = false;
			}
//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:XmlDriver.cs

示例3: Test3

	public static void Test3()
		{
		cert = TestCert ; 
		data = new KeyInfoX509Data( cert.Export( X509ContentType.Cert ) ) ;
		rv = ((X509Certificate2)data.Certificates[0]).ToString(true) == cert.ToString(true) ; 

		data = new KeyInfoX509Data( cert ) ; 
		rv = ((X509Certificate2)data.Certificates[0]).ToString(true) == cert.ToString(true) ; 
		}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:9,代码来源:x509datatest.cs

示例4: CreateInstances

	void CreateInstances()
		{
		bool res = false ; 
		string cd = Environment.CurrentDirectory + "\\" ; 
		X509Certificate2 real = null , fuzzed = null ; 
		string test = String.Empty ; 
		Result r = (Result) 0;
		string[] realFiles = GetFiles( cd , allCerts ) ;
		for( int i = 0 ; i < realFiles.Length ; i++ )
			{			
			string fileName = realFiles[i].ToUpper().Replace( cd.ToUpper() , String.Empty ) ; 
			string[] fuzzFiles = GetFiles( dir , fileName.Substring( 0 , fileName.IndexOf(".") ) + "-*.c*r*" ) ;
			try
				{
				real = new X509Certificate2( realFiles[i] ) ;
				}
			catch(Exception)
				{
				Console.WriteLine( realFiles[i] ) ; 
				break ; 
				}
			Console.WriteLine( "Going to test {0}" , realFiles[i] ) ; 
			for( int j = 0 ; j < fuzzFiles.Length ; j++ )
				{
				res= false ; 
				if( fuzzFiles[j].ToLower().IndexOf(".tmp" ) > 0 )
					{
					j++ ; 
					if( j == fuzzFiles.Length )
						break ; 
					}
				Console.WriteLine( "     with {0}" , fuzzFiles[j] ) ; 
				try
					{
					fuzzed = new X509Certificate2( fuzzFiles[j] ) ;
					fuzzed.Verify() ; 
					
					res = fuzzed.ToString(true).Equals(real.ToString(true)) ;
					r = res ? Result.Equals : Result.NotEquals ;
					test = fuzzFiles[i] + "    \n" ; 
					test += String.Format( "{0}\n\n!=\n\n{1}" , fuzzed.ToString(true),real.ToString(true) ) ;
					}
				catch(CryptographicException)
					{
					res = true ; 
					r = Result.CryptographicException ;
					}
				catch(Exception e)
					{
					Console.WriteLine(e) ; 
					r = Result.Exception ;
					}
				finally
					{
					Console.WriteLine( r ) ; 
					Eval( r!=Result.Exception , test ) ; 
					}
				}
			}
		}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:60,代码来源:X509FuzzTest.cs


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