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


C# X509Certificate2.GetKeyAlgorithm方法代码示例

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


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

示例1: 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

示例2: 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

示例3: TestGetKeyAlgorithm

 public static void TestGetKeyAlgorithm()
 {
     using (var c = new X509Certificate2(TestData.MsCertificate))
     {
         string keyAlgorithm = c.GetKeyAlgorithm();
         Assert.Equal("1.2.840.113549.1.1.1", keyAlgorithm);
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:PropsTests.cs

示例4: 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

示例5: 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

示例6: X509Cert2CreateFromPfxWithPassword

 public static void X509Cert2CreateFromPfxWithPassword()
 {
     using (X509Certificate2 cert2 = new X509Certificate2(Path.Combine("TestData", "test.pfx"), "test"))
     {
         // OID=RSA Encryption
         Assert.Equal("1.2.840.113549.1.1.1", cert2.GetKeyAlgorithm());
     }
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:CertTests.cs

示例7: X509Cert2CreateFromPfxFile

 public static void X509Cert2CreateFromPfxFile()
 {
     using (X509Certificate2 cert2 = new X509Certificate2(Path.Combine("TestData", "DummyTcpServer.pfx")))
     {
         // OID=RSA Encryption
         Assert.Equal("1.2.840.113549.1.1.1", cert2.GetKeyAlgorithm());
     }
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:CertTests.cs

示例8: 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

示例9: 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

示例10: 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

示例11: 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
VQQLDBJRWiBJbmR1c3RyaWVzLCBMTEMxGTAXBgNVBAMMEHF6aW5kdXN0cmllcy5j
b20xJzAlBgkqhkiG9w0BCQEWGHN1cHBvcnRAcXppbmR1c3RyaWVzLmNvbTAeFw0x
NjA0MDYyMTAwMDBaFw0xNzA0MDcyMTAwMDBaMIGtMQswCQYDVQQGDAJDWjEXMBUG
A1UECAwOQ3plY2ggUmVwdWJsaWMxDTALBgNVBAcMBEJybm8xGTAXBgNVBAoMEHNt
c3RpY2tldCBzLnIuby4xGTAXBgNVBAsMEHNtc3RpY2tldCBzLnIuby4xHjAcBgNV
BAMMFXBva2xhZG5hLnNtc3RpY2tldC5jejEgMB4GCSqGSIb3DQEJAQwRaW5mb0Bz
bXN0aWN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UAIrzynxO2vjYiMQxAUH3tdsX
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.GetKeyAlgorithm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。