Clears any secure memory associated with this object
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Sub Dispose() |
Example
Library/Library.Test/TestRSACrypto.cs
C# | Copy Code |
---|
string keyname = this.GetType().FullName + ".TestKeyCreateAndDelete";
using (RSAPrivateKey key = new RSAPrivateKey())
{
Assert.IsFalse(key.DeleteFromStore());
key.WriteToStore(keyname);
CspParameters cp = new CspParameters();
cp.KeyContainerName = keyname;
cp.Flags = CspProviderFlags.UseExistingKey;
using (RSAPrivateKey key2 = RSAPrivateKey.FromStore(cp))
Assert.AreEqual(key.ToXml(), key2.ToXml());
using (RSAPrivateKey key2 = RSAPrivateKey.FromStore(keyname))
{
Assert.AreEqual(key.ToXml(), key2.ToXml());
Assert.IsTrue(key2.DeleteFromStore());
key2.Dispose();
}
} |
VB.NET | Copy Code |
---|
Dim keyname As String = Me.[GetType]().FullName + ".TestKeyCreateAndDelete"
Using key As New RSAPrivateKey()
Assert.IsFalse(key.DeleteFromStore())
key.WriteToStore(keyname)
Dim cp As New CspParameters()
cp.KeyContainerName = keyname
cp.Flags = CspProviderFlags.UseExistingKey
Using key2 As RSAPrivateKey = RSAPrivateKey.FromStore(cp)
Assert.AreEqual(key.ToXml(), key2.ToXml())
End Using
Using key2 As RSAPrivateKey = RSAPrivateKey.FromStore(keyname)
Assert.AreEqual(key.ToXml(), key2.ToXml())
Assert.IsTrue(key2.DeleteFromStore())
key2.Dispose()
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also