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


C# X509Certificate2.GetNameInfo方法代码示例

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


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

示例1: X509Cert2Test

        public static void X509Cert2Test()
        {
            string certName = TestData.NormalizeX500String(
                @"[email protected], CN=ABA.ECOM Root CA, O=""ABA.ECOM, INC."", L=Washington, S=DC, C=US");

            DateTime notBefore = new DateTime(1999, 7, 12, 17, 33, 53, DateTimeKind.Utc).ToLocalTime();
            DateTime notAfter = new DateTime(2009, 7, 9, 17, 33, 53, DateTimeKind.Utc).ToLocalTime();

            using (X509Certificate2 cert2 = new X509Certificate2(Path.Combine("TestData", "test.cer")))
            {
                Assert.Equal(certName, cert2.IssuerName.Name);
                Assert.Equal(certName, cert2.SubjectName.Name);

                Assert.Equal("ABA.ECOM Root CA", cert2.GetNameInfo(X509NameType.DnsName, true));

                PublicKey pubKey = cert2.PublicKey;
                Assert.Equal("RSA", pubKey.Oid.FriendlyName);

                Assert.Equal(notAfter, cert2.NotAfter);
                Assert.Equal(notBefore, cert2.NotBefore);

                Assert.Equal("00D01E4090000046520000000100000004", cert2.SerialNumber);
                Assert.Equal("1.2.840.113549.1.1.5", cert2.SignatureAlgorithm.Value);
                Assert.Equal("7A74410FB0CD5C972A364B71BF031D88A6510E9E", cert2.Thumbprint);
                Assert.Equal(3, cert2.Version);
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:27,代码来源:CertTests.cs

示例2: EnsurePrivateKeyPreferred

 public static void EnsurePrivateKeyPreferred()
 {
     using (var cert = new X509Certificate2(TestData.ChainPfxBytes, TestData.ChainPfxPassword))
     {
         // While checking cert.HasPrivateKey first is most matching of the test description, asserting
         // on the certificate's simple name will provide a more diagnosable failure.
         Assert.Equal("test.local", cert.GetNameInfo(X509NameType.SimpleName, false));
         Assert.True(cert.HasPrivateKey, "cert.HasPrivateKey");
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:PfxTests.cs

示例3: TestComplexGetNameInfo

        private static void TestComplexGetNameInfo(string expected, X509NameType nameType, bool forIssuer)
        {
            // ComplexNameInfoCert has the following characteristics:
            //   Subject: [email protected], CN=cn.subject.example.org, OU=ExampleOU, O=ExampleO, L=Locality, ST=State, C=Country
            //   Issuer: [email protected], CN=cn.issuer.example.org, OU=ExampleOU, O=ExampleO, L=Locality, ST=State, C=Country
            //   Subject Alternative Names:
            //     DNS Name=dns1.subject.example.org
            //     DNS Name=dns2.subject.example.org
            //     RFC822 [email protected]
            //     RFC822 [email protected]
            //     Other Name:
            //       Principal [email protected]
            //     Other Name:
            //       Principal [email protected]
            //     URL=http://uri1.subject.example.org/
            //     URL=http://uri2.subject.example.org/
            //   Issuer Alternative Names:
            //     DNS Name=dns1.issuer.example.org
            //     DNS Name=dns2.issuer.example.org
            //     RFC822 [email protected]
            //     RFC822 [email protected]
            //     Other Name:
            //       Principal [email protected]
            //     Other Name:
            //       Principal [email protected]
            //     URL=http://uri1.issuer.example.org/
            //     URL=http://uri2.issuer.example.org/

            string result;

            using (var cert = new X509Certificate2(TestData.ComplexNameInfoCert))
            {
                result = cert.GetNameInfo(nameType, forIssuer);
            }

            Assert.Equal(expected, result);
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:37,代码来源:PropsTests.cs

示例4: TestGetNameInfo

        public static void TestGetNameInfo()
        {
            using (var c = new X509Certificate2(TestData.MsCertificate))
            {
                string s;

                s = c.GetNameInfo(X509NameType.SimpleName, false);
                Assert.Equal("Microsoft Corporation", s);
                s = c.GetNameInfo(X509NameType.SimpleName, true);
                Assert.Equal("Microsoft Code Signing PCA", s);

                s = c.GetNameInfo(X509NameType.EmailName, false);
                Assert.Equal("", s);
                s = c.GetNameInfo(X509NameType.EmailName, true);
                Assert.Equal("", s);

                s = c.GetNameInfo(X509NameType.UpnName, false);
                Assert.Equal("", s);
                s = c.GetNameInfo(X509NameType.UpnName, true);
                Assert.Equal("", s);

                s = c.GetNameInfo(X509NameType.UrlName, false);
                Assert.Equal("", s);
                s = c.GetNameInfo(X509NameType.UrlName, true);
                Assert.Equal("", s);

                s = c.GetNameInfo(X509NameType.DnsName, false);
                Assert.Equal("Microsoft Corporation", s);
                s = c.GetNameInfo(X509NameType.DnsName, true);
                Assert.Equal("Microsoft Code Signing PCA", s);
            }
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:32,代码来源:PropsTests.cs


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