本文整理汇总了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);
}