當前位置: 首頁>>代碼示例>>C#>>正文


C# CryptoKey.Dispose方法代碼示例

本文整理匯總了C#中OpenSSL.Crypto.CryptoKey.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# CryptoKey.Dispose方法的具體用法?C# CryptoKey.Dispose怎麽用?C# CryptoKey.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenSSL.Crypto.CryptoKey的用法示例。


在下文中一共展示了CryptoKey.Dispose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanGetAndSetProperties

		public void CanGetAndSetProperties()
		{
			int serial = 101;
			X509Name subject = new X509Name("CN=localhost");
			X509Name issuer = new X509Name("CN=Root");
			DateTime start = DateTime.Now;
			DateTime end = start + TimeSpan.FromMinutes(10);

			CryptoKey key = new CryptoKey(new DSA(true));
			int bits = key.Bits;

			X509Name saveIssuer = null;
			X509Name saveSubject = null;
			CryptoKey savePublicKey = null;
			CryptoKey savePrivateKey = null;
			using (X509Certificate cert = new X509Certificate()) {
				cert.Subject = subject;
				cert.Issuer = issuer;
				cert.SerialNumber = serial;
				cert.NotBefore = start;
				cert.NotAfter = end;
				cert.PublicKey = key;
				cert.PrivateKey = key;

				Assert.AreEqual(subject, cert.Subject);
				Assert.AreEqual(issuer, cert.Issuer);
				Assert.AreEqual(serial, cert.SerialNumber);

				Assert.AreEqual(key, cert.PublicKey);
				Assert.AreEqual(key, cert.PrivateKey);

				// If the original key gets disposed before the internal private key,
				// make sure that memory is correctly managed
				key.Dispose();

				// If the internal private key has already been disposed, this will blowup
				Assert.AreEqual(bits, cert.PublicKey.Bits);
				Assert.AreEqual(bits, cert.PrivateKey.Bits);

				// We compare short date/time strings here because the wrapper can't handle milliseconds
				Assert.AreEqual(start.ToShortDateString(), cert.NotBefore.ToShortDateString());
				Assert.AreEqual(start.ToShortTimeString(), cert.NotBefore.ToShortTimeString());

				saveSubject = cert.Subject;
				saveIssuer = cert.Issuer;
				savePublicKey = cert.PublicKey;
				savePrivateKey = cert.PrivateKey;
			}

			// make sure that a property torn-off from the cert is still valid
			Assert.AreEqual(subject, saveSubject);
			Assert.AreEqual(issuer, saveIssuer);
			Assert.AreEqual(bits, savePublicKey.Bits);
			Assert.AreEqual(bits, savePrivateKey.Bits);
		}
開發者ID:challal,項目名稱:scallion,代碼行數:55,代碼來源:TestX509Certificate.cs


注:本文中的OpenSSL.Crypto.CryptoKey.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。