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


C# X509Certificate2.GetKeyAlgorithmParameters方法代码示例

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


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

示例1: TestByteArrayConstructor

        public static void TestByteArrayConstructor()
        {
            byte[] expectedThumbPrint = new byte[]
            {
                0x10, 0x8e, 0x2b, 0xa2, 0x36, 0x32, 0x62, 0x0c,
                0x42, 0x7c, 0x57, 0x0b, 0x6d, 0x9d, 0xb5, 0x1a,
                0xc3, 0x13, 0x87, 0xfe,
            };

            using (X509Certificate2 c = new X509Certificate2(TestData.MsCertificate))
            {
                IntPtr h = c.Handle;
                object ignored;
                Assert.NotEqual(IntPtr.Zero, h);
                byte[] actualThumbprint = c.GetCertHash();
                Assert.Equal(expectedThumbPrint, actualThumbprint);

                c.Dispose();

                // For compat reasons, Dispose() acts like the now-defunct Reset() method rather than causing ObjectDisposedExceptions.
                h = c.Handle;
                Assert.Equal(IntPtr.Zero, h);
                Assert.Throws<CryptographicException>(() => c.GetCertHash());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithm());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParameters());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParametersString());
                Assert.Throws<CryptographicException>(() => c.GetPublicKey());
                Assert.Throws<CryptographicException>(() => c.GetSerialNumber());
                Assert.Throws<CryptographicException>(() => ignored = c.Issuer);
                Assert.Throws<CryptographicException>(() => ignored = c.Subject);
            }
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:32,代码来源:CtorTests.cs

示例2: TestDefaultConstructor

 public static void TestDefaultConstructor()
 {
     using (X509Certificate2 c = new X509Certificate2())
     {
         IntPtr h = c.Handle;
         object ignored;
         Assert.Equal(IntPtr.Zero, h);
         Assert.Throws<CryptographicException>(() => c.GetCertHash());
         Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithm());
         Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParameters());
         Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParametersString());
         Assert.Throws<CryptographicException>(() => c.GetPublicKey());
         Assert.Throws<CryptographicException>(() => c.GetSerialNumber());
         Assert.Throws<CryptographicException>(() => ignored = c.Issuer);
         Assert.Throws<CryptographicException>(() => ignored = c.Subject);
         Assert.Throws<CryptographicException>(() => ignored = c.RawData);
         Assert.Throws<CryptographicException>(() => ignored = c.Thumbprint);
         Assert.Throws<CryptographicException>(() => ignored = c.SignatureAlgorithm);
         Assert.Throws<CryptographicException>(() => ignored = c.HasPrivateKey);
         Assert.Throws<CryptographicException>(() => ignored = c.Version);
         Assert.Throws<CryptographicException>(() => ignored = c.Archived);
         Assert.Throws<CryptographicException>(() => c.Archived = false);
         Assert.Throws<CryptographicException>(() => c.FriendlyName = "Hi");
         Assert.Throws<CryptographicException>(() => ignored = c.SubjectName);
         Assert.Throws<CryptographicException>(() => ignored = c.IssuerName);
         Assert.Throws<CryptographicException>(() => ignored = c.PrivateKey);
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:28,代码来源:CtorTests.cs

示例3: UseAfterDispose

        public static void UseAfterDispose()
        {
            using (X509Certificate2 c = new X509Certificate2(TestData.MsCertificate))
            {
                IntPtr h = c.Handle;

                // Do a couple of things that would only be true on a valid certificate, as a precondition.
                Assert.NotEqual(IntPtr.Zero, h);
                byte[] actualThumbprint = c.GetCertHash();

                c.Dispose();

                // For compat reasons, Dispose() acts like the now-defunct Reset() method rather than
                // causing ObjectDisposedExceptions.
                h = c.Handle;
                Assert.Equal(IntPtr.Zero, h);

                // State held on X509Certificate
                Assert.ThrowsAny<CryptographicException>(() => c.GetCertHash());
                Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithm());
                Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithmParameters());
                Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithmParametersString());
                Assert.ThrowsAny<CryptographicException>(() => c.GetPublicKey());
                Assert.ThrowsAny<CryptographicException>(() => c.GetSerialNumber());
                Assert.ThrowsAny<CryptographicException>(() => c.Issuer);
                Assert.ThrowsAny<CryptographicException>(() => c.Subject);
                Assert.ThrowsAny<CryptographicException>(() => c.NotBefore);
                Assert.ThrowsAny<CryptographicException>(() => c.NotAfter);

                // State held on X509Certificate2
                Assert.ThrowsAny<CryptographicException>(() => c.RawData);
                Assert.ThrowsAny<CryptographicException>(() => c.SignatureAlgorithm);
                Assert.ThrowsAny<CryptographicException>(() => c.Version);
                Assert.ThrowsAny<CryptographicException>(() => c.SubjectName);
                Assert.ThrowsAny<CryptographicException>(() => c.IssuerName);
                Assert.ThrowsAny<CryptographicException>(() => c.PublicKey);
                Assert.ThrowsAny<CryptographicException>(() => c.Extensions);
            #if netstandard17
                Assert.ThrowsAny<CryptographicException>(() => c.PrivateKey);
            #endif
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:42,代码来源:CertTests.cs

示例4: VerifyDefaultConstructor

        private static void VerifyDefaultConstructor(X509Certificate2 c)
        {
            IntPtr h = c.Handle;
            object ignored;
            Assert.Equal(IntPtr.Zero, h);
            Assert.ThrowsAny<CryptographicException>(() => c.GetCertHash());
            Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithm());
            Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithmParameters());
            Assert.ThrowsAny<CryptographicException>(() => c.GetKeyAlgorithmParametersString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetPublicKey());
            Assert.ThrowsAny<CryptographicException>(() => c.GetSerialNumber());
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.Issuer);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.Subject);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.RawData);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.Thumbprint);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.SignatureAlgorithm);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.HasPrivateKey);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.Version);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.Archived);
            Assert.ThrowsAny<CryptographicException>(() => c.Archived = false);
            Assert.ThrowsAny<CryptographicException>(() => c.FriendlyName = "Hi");
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.SubjectName);
            Assert.ThrowsAny<CryptographicException>(() => ignored = c.IssuerName);
#if netstandard17
            Assert.ThrowsAny<CryptographicException>(() => c.GetCertHashString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetEffectiveDateString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetExpirationDateString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetPublicKeyString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetRawCertData());
            Assert.ThrowsAny<CryptographicException>(() => c.GetRawCertDataString());
            Assert.ThrowsAny<CryptographicException>(() => c.GetSerialNumberString());
#pragma warning disable 0618
            Assert.ThrowsAny<CryptographicException>(() => c.GetIssuerName());
            Assert.ThrowsAny<CryptographicException>(() => c.GetName());
#pragma warning restore 0618
#endif
        }
开发者ID:chcosta,项目名称:corefx,代码行数:37,代码来源:CtorTests.cs

示例5: TestGetKeyAlgorithmParameters

        public static void TestGetKeyAlgorithmParameters()
        {
            string expected = "0500";

            using (var c = new X509Certificate2(TestData.MsCertificate))
            {
                byte[] keyAlgorithmParameters = c.GetKeyAlgorithmParameters();
                Assert.Equal(expected.HexToByteArray(), keyAlgorithmParameters);

                string keyAlgorithmParametersString = c.GetKeyAlgorithmParametersString();
                Assert.Equal(expected, keyAlgorithmParametersString);
            }
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:13,代码来源:PropsTests.cs

示例6: TestCopyConstructor_Pal

        public static void TestCopyConstructor_Pal()
        {
            using (var c1 = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
            using (var c2 = new X509Certificate2(c1))
            {
                Assert.Equal(c1.GetCertHash(), c2.GetCertHash());
                Assert.Equal(c1.GetKeyAlgorithm(), c2.GetKeyAlgorithm());
                Assert.Equal(c1.GetKeyAlgorithmParameters(), c2.GetKeyAlgorithmParameters());
                Assert.Equal(c1.GetKeyAlgorithmParametersString(), c2.GetKeyAlgorithmParametersString());
                Assert.Equal(c1.GetPublicKey(), c2.GetPublicKey());
                Assert.Equal(c1.GetSerialNumber(), c2.GetSerialNumber());
                Assert.Equal(c1.Issuer, c2.Issuer);
                Assert.Equal(c1.Subject, c2.Subject);
                Assert.Equal(c1.RawData, c2.RawData);
                Assert.Equal(c1.Thumbprint, c2.Thumbprint);
                Assert.Equal(c1.SignatureAlgorithm.Value, c2.SignatureAlgorithm.Value);
                Assert.Equal(c1.HasPrivateKey, c2.HasPrivateKey);
                Assert.Equal(c1.Version, c2.Version);
                Assert.Equal(c1.Archived, c2.Archived);
                Assert.Equal(c1.SubjectName.Name, c2.SubjectName.Name);
                Assert.Equal(c1.IssuerName.Name, c2.IssuerName.Name);
                Assert.Equal(c1.GetCertHashString(), c2.GetCertHashString());
                Assert.Equal(c1.GetEffectiveDateString(), c2.GetEffectiveDateString());
                Assert.Equal(c1.GetExpirationDateString(), c2.GetExpirationDateString());
                Assert.Equal(c1.GetPublicKeyString(), c2.GetPublicKeyString());
                Assert.Equal(c1.GetRawCertData(), c2.GetRawCertData());
                Assert.Equal(c1.GetRawCertDataString(), c2.GetRawCertDataString());
                Assert.Equal(c1.GetSerialNumberString(), c2.GetSerialNumberString());
#pragma warning disable 0618
                Assert.Equal(c1.GetIssuerName(), c2.GetIssuerName());
                Assert.Equal(c1.GetName(), c2.GetName());
#pragma warning restore 0618
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:34,代码来源:CtorTests.cs

示例7: UseAfterDispose

        public static void UseAfterDispose()
        {
            using (X509Certificate2 c = new X509Certificate2(TestData.MsCertificate))
            {
                IntPtr h = c.Handle;

                // Do a couple of things that would only be true on a valid certificate, as a precondition.
                Assert.NotEqual(IntPtr.Zero, h);
                byte[] actualThumbprint = c.GetCertHash();

                c.Dispose();

                // For compat reasons, Dispose() acts like the now-defunct Reset() method rather than
                // causing ObjectDisposedExceptions.
                h = c.Handle;
                Assert.Equal(IntPtr.Zero, h);
                Assert.Throws<CryptographicException>(() => c.GetCertHash());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithm());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParameters());
                Assert.Throws<CryptographicException>(() => c.GetKeyAlgorithmParametersString());
                Assert.Throws<CryptographicException>(() => c.GetPublicKey());
                Assert.Throws<CryptographicException>(() => c.GetSerialNumber());
                Assert.Throws<CryptographicException>(() => c.Issuer);
                Assert.Throws<CryptographicException>(() => c.Subject);
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:26,代码来源:CertTests.cs

示例8: GetPublicKey_X509Signature_NoParameters

        public static void GetPublicKey_X509Signature_NoParameters()
        {
            // Normally RSA signature AlgorithmIdentifiers get represented as
            //
            // SEQUENCE(
            //    algorithm: OID(1.2.840.113549.1.1.5),
            //    parameters: NULL)
            //
            // where parameters: NULL is the byte sequence 05 00.
            //
            // This certificate has omitted the parameters section completely,
            // which while RFC compliant (it's labelled OPTIONAL) isn't what everyone
            // else does.  So this test ensures that we can read such a cert.
            const string PemEncodedCert = @"
-----BEGIN CERTIFICATE-----
MIIE4jCCAsygAwIBAgIEMTI0NjALBgkqhkiG9w0BAQUwgZgxCzAJBgNVBAYTAlVT
MQswCQYDVQQIDAJOWTEbMBkGA1UECgwSUVogSW5kdXN0cmllcywgTExDMRswGQYD
VQQLDBJR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iGoexz0Ia51M5cw5W5go2Abmtqs4bbz
7OFeZKP9fd1p+C/ZnekgKq+3SJ9qbEiJxoPir3rG2N0mw7iI5pwvbCixY9irZh5o
Lrc5RvH4hdpygNSm4MYEuBykEW0tizkcVanGCUmGdjxM22Y9XdPgKitS04rVk/2U
C1Gszv9KvtmQ2P3/HWWWiOQgljc3SFqBltt6TqJTGCtLEbWRw6V+sw3SALoafvLg
tIsyWUsjM5LunRkUQ+HIsmKo42943TmgUvgRuuo0nsEFI5TS7Jh0iC/2gQEt7XGh
wzOTZ0HzM3oNnTphlXFLBwL9MUgWKbhu5Fg486dDMeQmZmhztW/+F/uHHYFisk+1
tmr2prSh5i4fD71t4p+EGJJQxM4wCiXRLzggIVGUAIrzynxO2vjYiMQxAUH3tdsX
JI6fq+e/mFZOE2XQmYu3/hQEw8/2F6usF1lyvwMZt2TgQZF1/g8gFVQUY2mGLM1z
Wry5FNNo
-----END CERTIFICATE-----";

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(PemEncodedCert);

            using (X509Certificate2 cert = new X509Certificate2(bytes))
            {
                Assert.Equal(Array.Empty<byte>(), cert.GetKeyAlgorithmParameters());
                Assert.Equal("1.2.840.113549.1.1.1", cert.GetKeyAlgorithm());
            }
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:52,代码来源:PropsTests.cs


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