CSharpTest.Net
FromStore Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > RSAPrivateKey Class : FromStore Method

name

Glossary Item Box

Creates the key from the information provided

Syntax

Visual Basic (Declaration) 
Public Shared Shadows Function FromStore( _
   ByVal name As String _
) As RSAPrivateKey
C# 
public new static RSAPrivateKey FromStore( 
   string name
)

Parameters

name

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.NETCopy 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

Generated with Document! X 2011 by Innovasys