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


C# X509Extension.Format方法代码示例

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


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

示例1: X509SubjectAlternativeNameConstants

            // static initializer runs only when one of the properties is accessed
            static X509SubjectAlternativeNameConstants()
            {
                // Extracted a well-known X509Extension
                byte[] x509ExtensionBytes = new byte[] {
                    48, 36, 130, 21, 110, 111, 116, 45, 114, 101, 97, 108, 45, 115, 117, 98, 106, 101, 99,
                    116, 45, 110, 97, 109, 101, 130, 11, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109
                };
                const string subjectName1 = "not-real-subject-name";

                try
                {
                    X509Extension x509Extension = new X509Extension(Oid, x509ExtensionBytes, true);
                    string x509ExtensionFormattedString = x509Extension.Format(false);

                    // Each OS has a different dNSName identifier and delimiter
                    // On Windows, dNSName == "DNS Name" (localizable), on Linux, dNSName == "DNS"
                    // e.g.,
                    // Windows: x509ExtensionFormattedString is: "DNS Name=not-real-subject-name, DNS Name=example.com"
                    // Linux:   x509ExtensionFormattedString is: "DNS:not-real-subject-name, DNS:example.com"
                    // Parse: <identifier><delimter><value><separator(s)>

                    int delimiterIndex = x509ExtensionFormattedString.IndexOf(subjectName1) - 1;
                    _delimiter = x509ExtensionFormattedString[delimiterIndex];

                    // Make an assumption that all characters from the the start of string to the delimiter 
                    // are part of the identifier
                    _identifier = x509ExtensionFormattedString.Substring(0, delimiterIndex);

                    int separatorFirstChar = delimiterIndex + subjectName1.Length + 1;
                    int separatorLength = 1;
                    for (int i = separatorFirstChar + 1; i < x509ExtensionFormattedString.Length; i++)
                    {
                        // We advance until the first character of the identifier to determine what the
                        // separator is. This assumes that the identifier assumption above is correct
                        if (x509ExtensionFormattedString[i] == _identifier[0])
                        {
                            break;
                        }
                        
                        separatorLength++;
                    }

                    _separator = x509ExtensionFormattedString.Substring(separatorFirstChar, separatorLength);

                    _successfullyInitialized = true;
                }
                catch (Exception ex)
                {
                    _successfullyInitialized = false;
                    _initializationException = ex;
                }
            }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:53,代码来源:X509CertificateClaimSet.cs

示例2: ConstructorAsnEncodedData_BadAsnLength

		public void ConstructorAsnEncodedData_BadAsnLength ()
		{
			AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x01 });
			X509Extension ex = new X509Extension (aed, true);
			Assert.AreEqual ("30 01", ex.Format (true), "Format(true)");
			Assert.AreEqual ("30 01", ex.Format (false), "Format(false)");
			// no exception for an bad (invalid length) extension
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:X509ExtensionTest.cs

示例3: ConstructorAsnEncodedData_BadAsn

		public void ConstructorAsnEncodedData_BadAsn ()
		{
			AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]);
			X509Extension ex = new X509Extension (aed, true);
			Assert.AreEqual (String.Empty, ex.Format (true), "Format(true)");
			Assert.AreEqual (String.Empty, ex.Format (false), "Format(false)");
			// no exception for an "empty" extension
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:X509ExtensionTest.cs

示例4: ConstructorAsnEncodedData_BadAsnTag

		public void ConstructorAsnEncodedData_BadAsnTag ()
		{
			AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 });
			X509Extension ex = new X509Extension (aed, true);
			Assert.AreEqual ("05 00", ex.Format (true), "Format(true)");
			Assert.AreEqual ("05 00", ex.Format (false), "Format(false)");
			// no exception for an "unknown" (ASN.1 NULL) extension
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:X509ExtensionTest.cs

示例5: X509SubjectAlternativeNameConstants

            // static initializer runs only when one of the properties is accessed
            static X509SubjectAlternativeNameConstants()
            {
                // Extracted a well-known X509Extension
                const string x509ExtensionBase64String = "MCSCFW5vdC1yZWFsLXN1YmplY3QtbmFtZYILZXhhbXBsZS5jb20=";
                const string subjectName1 = "not-real-subject-name";

                X509Extension x509Extension = new X509Extension(Oid, Convert.FromBase64String(x509ExtensionBase64String), true);
                string x509ExtensionFormattedString = x509Extension.Format(false);

                // Each OS has a different dNSName identifier and delimiter
                // On Windows, dNSName == "DNS Name" (localizable), on Linux, dNSName == "DNS"
                // e.g.,
                // Windows: x509ExtensionFormattedString is: "DNS Name=not-real-subject-name, DNS Name=example.com"
                // Linux:   x509ExtensionFormattedString is: "DNS:not-real-subject-name, DNS:example.com"
                // Parse: <identifier><delimter><value><separator(s)>

                int delimiterIndex = x509ExtensionFormattedString.IndexOf(subjectName1) - 1;
                Delimiter = x509ExtensionFormattedString[delimiterIndex];

                // Make an assumption that all characters from the the start of string to the delimiter 
                // are part of the identifier
                Identifier = x509ExtensionFormattedString.Substring(0, delimiterIndex);

                int separatorFirstChar = delimiterIndex + subjectName1.Length + 1;
                int separatorLength = 1;
                for (int i = separatorFirstChar + 1; i < x509ExtensionFormattedString.Length; i++)
                {
                    // We advance until the first character of the identifier to determine what the
                    // separator is. This assumes that the identifier assumption above is correct
                    if (x509ExtensionFormattedString[i] == Identifier[0])
                    {
                        break;
                    }
                    else
                    {
                        separatorLength++;
                    }
                }

                Separator = x509ExtensionFormattedString.Substring(separatorFirstChar, separatorLength);
            }
开发者ID:SajayAntony,项目名称:wcf,代码行数:42,代码来源:X509CertificateClaimSet.cs

示例6: X509SubjectAlternativeNameConstants

            // static initializer will run before properties are accessed
            static X509SubjectAlternativeNameConstants()
            {
                // Extracted a well-known X509Extension
                byte[] x509ExtensionBytes = new byte[] {
                    48, 36, 130, 21, 110, 111, 116, 45, 114, 101, 97, 108, 45, 115, 117, 98, 106, 101, 99,
                    116, 45, 110, 97, 109, 101, 130, 11, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109
                };
                const string subjectName = "not-real-subject-name";
                string x509ExtensionFormattedString = string.Empty;
                try
                {
                    X509Extension x509Extension = new X509Extension(SanOid, x509ExtensionBytes, true);
                    x509ExtensionFormattedString = x509Extension.Format(false);

                    // Each OS has a different dNSName identifier and delimiter
                    // On Windows, dNSName == "DNS Name" (localizable), on Linux, dNSName == "DNS"
                    // e.g.,
                    // Windows: x509ExtensionFormattedString is: "DNS Name=not-real-subject-name, DNS Name=example.com"
                    // Linux:   x509ExtensionFormattedString is: "DNS:not-real-subject-name, DNS:example.com"
                    // Parse: <identifier><delimiter><value><separator(s)>

                    int delimiterIndex = x509ExtensionFormattedString.IndexOf(subjectName) - 1;
                    Delimiter = x509ExtensionFormattedString[delimiterIndex];

                    // Make an assumption that all characters from the the start of string to the delimiter 
                    // are part of the identifier
                    Identifier = x509ExtensionFormattedString.Substring(0, delimiterIndex);

                    int separatorFirstChar = delimiterIndex + subjectName.Length + 1;
                    int separatorLength = 1;
                    for (int i = separatorFirstChar + 1; i < x509ExtensionFormattedString.Length; i++)
                    {
                        // We advance until the first character of the identifier to determine what the
                        // separator is. This assumes that the identifier assumption above is correct
                        if (x509ExtensionFormattedString[i] == Identifier[0])
                        {
                            break;
                        }

                        separatorLength++;
                    }

                    Separator = x509ExtensionFormattedString.Substring(separatorFirstChar, separatorLength);
                    SeparatorArray = new string[1] { Separator };
                    SuccessfullyInitialized = true;
                }
                catch (Exception ex)
                {
                    SuccessfullyInitialized = false;                    
                    DiagnosticUtility.TraceHandledException(
                        new FormatException(string.Format(CultureInfo.InvariantCulture,
                        "There was an error parsing the SubjectAlternativeNames: '{0}'. See inner exception for more details.{1}Detected values were: Identifier: '{2}'; Delimiter:'{3}'; Separator:'{4}'",
                        x509ExtensionFormattedString,
                        Environment.NewLine,
                        Identifier,
                        Delimiter,
                        Separator),
                        ex), 
                        TraceEventType.Warning);
                }
            }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:62,代码来源:X509CertificateClaimSet.cs

示例7: ConstructorAsnEncodedData

		public void ConstructorAsnEncodedData ()
		{
			AsnEncodedData aed = new AsnEncodedData (new Oid ("2.5.29.37"), new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 });
			X509Extension ex = new X509Extension (aed, true);
			Assert.IsTrue (ex.Critical, "Critical");
			Assert.AreEqual (7, ex.RawData.Length, "RawData");	// original Oid ignored
			Assert.AreEqual ("2.5.29.37", ex.Oid.Value, "Oid.Value");
			Assert.AreEqual ("Enhanced Key Usage", ex.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, ex.Format (true), "Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", ex.Format (false), "Format(false)");
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:11,代码来源:X509ExtensionTest.cs

示例8: Build_NetscapeCertTypeExtension

		public void Build_NetscapeCertTypeExtension ()
		{
			X509Extension ex = new X509Extension (new Oid ("2.16.840.1.113730.1.1"), new byte[] { 0x03, 0x02, 0x00, 0xFF }, false);
			// strangely no NewLine is being appended to Format(true)
			Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (true), "aed.Format(true)");
			Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (false), "aed.Format(false)");
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:X509ExtensionTest.cs


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