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


C# AsnEncodedData.Format方法代码示例

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


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

示例1: Constructor_StringData

		public void Constructor_StringData ()
		{
			AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
			Assert.AreEqual ("oid", aed.Oid.Value, "Oid.Value");
			Assert.IsNull (aed.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData");
			Assert.AreEqual (asnNullString, aed.Format (true), "Format");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:AsnEncodedDataTest.cs

示例2: Build_SubjectAltNameExtension

		[Category ("NotDotNet")] // FriendlyName should not only be English.
		// note: important to emulate in Mono because we need it for SSL/TLS
		public void Build_SubjectAltNameExtension ()
		{
			AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x16, 0x82, 0x14, 0x77, 0x77, 0x77, 0x2E, 0x6D, 0x6F, 0x6E, 0x6F, 0x2D, 0x70, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x2E, 0x63, 0x6F, 0x6D });
			Assert.AreEqual ("30 16 82 14 77 77 77 2e 6d 6f 6e 6f 2d 70 72 6f 6a 65 63 74 2e 63 6f 6d", aed.Format (true), "Format(true)");
			Assert.AreEqual ("30 16 82 14 77 77 77 2e 6d 6f 6e 6f 2d 70 72 6f 6a 65 63 74 2e 63 6f 6d", aed.Format (false), "Format(false)");
			aed.Oid = new Oid ("2.5.29.17");
			// and now "AsnEncodedData" knows how to (magically) decode the data without involving the class
			Assert.AreEqual ("DNS Name=www.mono-project.com" + Environment.NewLine, aed.Format (true), "aed.Format(true)");
			Assert.AreEqual ("DNS Name=www.mono-project.com", aed.Format (false), "aed.Format(false)");
			// note that the Fx doesn't "really" support this extension
			// finally this also means that the Oid "knowns" about oid not used in the Fx itself
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Subject Alternative Name", aed.Oid.FriendlyName, "FriendlyName");
			// anyway the answer is most probably CryptoAPI
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:AsnEncodedDataTest.cs

示例3: Build_X509EnhancedKeyUsageExtension

		[Category ("NotDotNet")] // FriendlyName should not only be English.
		public void Build_X509EnhancedKeyUsageExtension ()
		{
			AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 });
			Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (true), "Format(true)");
			Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (false), "Format(false)");
			aed.Oid = new Oid ("2.5.29.37");
			// and now "AsnEncodedData" knows how to (magically) decode the data without involving the class
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, aed.Format (true), "aed.Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", aed.Format (false), "aed.Format(false)");
			// compare with the output of the "appropriate" class
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, false);
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, eku.Format (true), "eku.Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", eku.Format (false), "eku.Format(false)");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:AsnEncodedDataTest.cs

示例4: Build_NetscapeCertTypeExtension

		[Category ("NotDotNet")] // FriendlyName should not only be English.
		// note: important to emulate in Mono because we need it for SSL/TLS
		public void Build_NetscapeCertTypeExtension ()
		{
			AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x03, 0x02, 0x01, 0x06 });
			Assert.AreEqual ("03 02 01 06", aed.Format (true), "Format(true)");
			Assert.AreEqual ("03 02 01 06", aed.Format (false), "Format(false)");
			aed.Oid = new Oid ("2.16.840.1.113730.1.1");
			// and now "AsnEncodedData" knows how to (magically) decode the data without involving the class
			Assert.AreEqual ("SSL CA, SMIME CA (06)", aed.Format (true), "aed.Format(true)");
			Assert.AreEqual ("SSL CA, SMIME CA (06)", aed.Format (false), "aed.Format(false)");
			// note that the Fx doesn't "really" support this extension
			// and strangely no NewLine is being appended to Format(true)
			// finally this also means that the Oid "knowns" about oid not used in the Fx itself
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Netscape Cert Type", aed.Oid.FriendlyName, "FriendlyName");
			// anyway the answer is most probably CryptoAPI
		}
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:AsnEncodedDataTest.cs

示例5: CopyFrom

		public void CopyFrom ()
		{
			Oid o = new Oid ("1.2.3");
			byte[] data = (byte[])asnNullBytes.Clone ();
			AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
			AsnEncodedData copy = new AsnEncodedData ((Oid)null, new byte [0]);
			copy.CopyFrom (aed);

			Assert.AreEqual (aed.Oid.Value, copy.Oid.Value, "Oid 1");
			Assert.AreEqual (aed.Format (true), copy.Format (true), "Format 1");

			aed.Oid = new Oid ("1.2.4");
			aed.RawData = new byte[1];

			Assert.AreEqual ("1.2.3", copy.Oid.Value, "Oid 2");
			Assert.AreEqual (asnNullString, copy.Format (true), "Format 2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:AsnEncodedDataTest.cs

示例6: FormatMultiline

		public void FormatMultiline ()
		{
			AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
			Assert.AreEqual ("1.2.840.113549.1.1.1", aed.Oid.Value, "Oid.Value");
			Assert.AreEqual ("RSA", aed.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (BitConverter.ToString (asnLongBytes), BitConverter.ToString (aed.RawData), "RawData");
			string result = aed.Format (true);
			Assert.AreEqual (asnLongString, result, "Format(true)");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:AsnEncodedDataTest.cs

示例7: RawData_CanModify

		public void RawData_CanModify ()
		{
			byte[] data = (byte[])asnNullBytes.Clone ();
			AsnEncodedData aed = new AsnEncodedData ("1.2.3", data);
			Assert.AreEqual (asnNullString, aed.Format (true), "Format 1");
			data[0] = 0x06;
			Assert.AreEqual (asnNullString, aed.Format (true), "Format 2"); ; // didn't change (copy)
			aed.RawData[0] = 0x07;
			Assert.AreEqual ("07 00", aed.Format (true), "Format 3"); // changed!
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:AsnEncodedDataTest.cs

示例8: Parse

 private void Parse(byte[] data)
 {
     if (base.Oid.Value == SubjectAltNameOid ||
         base.Oid.Value == SubjectAltName2Oid)
     {
         AsnEncodedData asnData = new AsnEncodedData(base.Oid.Value, data);
         string formattedData = asnData.Format(false);
         ParseSubjectAltNameUsageExtension(formattedData);
     }
     else
     {
         throw new ServiceResultException(
             StatusCodes.BadCertificateInvalid,
             "Certificate uses unknown SubjectAltNameOid.");
     }
 }
开发者ID:OPCFoundation,项目名称:UA-.NETStandardLibrary,代码行数:16,代码来源:X509SubjectAltNameExtension.cs

示例9: Parse

 private void Parse(byte[] data)
 {
     if (base.Oid.Value == AuthorityKeyIdentifierOid ||
         base.Oid.Value == AuthorityKeyIdentifier2Oid)
     {
         AsnEncodedData asnData = new AsnEncodedData(base.Oid.Value, data);
         string formattedData = asnData.Format(false);
         ParseAuthorityKeyIdentifierExtension(formattedData);
     }
     else
     {
         throw new ServiceResultException(
             StatusCodes.BadCertificateInvalid,
             "Certificate uses unknown AuthorityKeyIdentifierOid.");
     }
 }
开发者ID:OPCFoundation,项目名称:UA-.NETStandardLibrary,代码行数:16,代码来源:X509AuthorityKeyIdentifierExtension.cs

示例10: Constructor_Asn

		public void Constructor_Asn () 
		{
			AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
			AsnEncodedData aed2 = new AsnEncodedData (aed);
			Assert.AreEqual (aed.Oid.Value, aed2.Oid.Value, "Oid.Value");
			Assert.AreEqual (aed.Oid.FriendlyName, aed2.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (BitConverter.ToString (aed.RawData), BitConverter.ToString (aed2.RawData), "RawData");
			string s1 = aed.Format (false); 
			string s2 = aed.Format (true);
			Assert.AreEqual (s1, s2, "Format");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:AsnEncodedDataTest.cs

示例11: CertificateValidationCallBack

        private static bool CertificateValidationCallBack(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            // Certificate2 is better than Certificate1, right?
            X509Certificate2 cert = (X509Certificate2)certificate;

            string[] subjectPieces = splitDN(cert.Subject);

            Console.Write("Certificate Subject   : ");
            for (int x = 0; x < subjectPieces.Length; x++)
            {
                if (x == 0)
                    Console.WriteLine(subjectPieces[x]);
                else
                    Console.WriteLine("                        " + subjectPieces[x]);
            }

            string[] issuerPieces = splitDN(cert.Issuer);

            Console.Write("Certificate Issuer    : ");
            for (int x = 0; x < issuerPieces.Length; x++)
            {
                if (x == 0)
                    Console.WriteLine(issuerPieces[x]);
                else
                    Console.WriteLine("                        " + issuerPieces[x]);
            }

            Console.WriteLine("Certificate Begins    : " + cert.NotBefore);
            Console.WriteLine("Certificate Expires   : " + cert.NotAfter);
            Console.WriteLine("Certificate Version   : " + cert.Version);
            if (cert.SignatureAlgorithm.FriendlyName.ToLower().Contains("md5"))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Signature Algorithm   : " + cert.SignatureAlgorithm.FriendlyName + " (" + cert.SignatureAlgorithm.Value + ")");
                Console.ResetColor();
            }
            else
            {
                Console.WriteLine("Signature Algorithm   : " + cert.SignatureAlgorithm.FriendlyName + " (" + cert.SignatureAlgorithm.Value + ")");
            }
            Console.WriteLine("Key Exchange Algorithm: " + cert.PublicKey.Key.KeyExchangeAlgorithm);
            Console.WriteLine("Public Key Algorithm  : " + new System.Security.Cryptography.Oid(cert.GetKeyAlgorithm()).FriendlyName);
            Console.WriteLine("Public Key Size       : " + cert.PublicKey.Key.KeySize);
            foreach (X509Extension extension in cert.Extensions)
            {
                if (extension.Oid.FriendlyName == "Subject Alternative Name")
                {
                    AsnEncodedData asnData = new AsnEncodedData(extension.Oid, extension.RawData);
                    string[] sans = asnData.Format(false).Split(',');
                    Console.Write("Alternative Names     : ");
                    for (int x = 0; x < sans.Length; x++)
                    {
                        if (x == 0)
                            Console.WriteLine(sans[x]);
                        else
                            Console.WriteLine("                       " + sans[x]);
                    }
                }
            }
            Console.Write("Certificate Validated : ");
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Yes");
                Console.ResetColor();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No (" + sslPolicyErrors + ")");
                Console.ResetColor();
            }
            return true;
        }
开发者ID:ryanries,项目名称:SharpTLSScan,代码行数:74,代码来源:Program.cs

示例12: GetElementInX509Name

 public static string GetElementInX509Name(X509Certificate2 certificate, string element)
 {
     var asnEncodedData = new AsnEncodedData(new Oid(element), certificate.SubjectName.RawData);
     return asnEncodedData.Format(false);
 }
开发者ID:kiniry-supervision,项目名称:OpenNemID,代码行数:5,代码来源:X509CertificatePropertyExtrator.cs

示例13: GetSubjectCommonName

 public static string GetSubjectCommonName(X509Certificate2 certificate)
 {
     var asnEncodedData = new AsnEncodedData(new Oid(ObjectIdentifiers.CommonName), certificate.SubjectName.RawData);
     return asnEncodedData.Format(false);
 }
开发者ID:kiniry-supervision,项目名称:OpenNemID,代码行数:5,代码来源:X509CertificatePropertyExtrator.cs

示例14: Constructor_OidNullData

		public void Constructor_OidNullData () 
		{
			// this is legal - http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=38336cfa-3b97-47da-ad4e-9522d557f001
			Oid o = null;
			AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
			Assert.IsNull (aed.Oid, "Oid");
			Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData");
			Assert.AreEqual (asnNullString, aed.Format (true), "Format");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:AsnEncodedDataTest.cs

示例15: RawData

		public void RawData ()
		{
			AsnEncodedData aed = new AsnEncodedData ((Oid)null, asnNullBytes);
			Assert.AreEqual (asnNullString, aed.Format (true), "Format 1");
			aed.RawData = null;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:6,代码来源:AsnEncodedDataTest.cs


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