This documentation is archived and is not being maintained.

CspParameters.KeyContainerName Field

Represents the key container name for CspParameters.

[Visual Basic]
Public KeyContainerName As String
[C#]
public string KeyContainerName;
[C++]
public: String* KeyContainerName;
[JScript]
public var KeyContainerName : String;

Remarks

Refer to the Windows Cryptography API documentation for details on key containers.

Example

[Visual Basic] 
Imports System
Imports System.IO
Imports System.Security.Cryptography



Public Class StoreKey
    
    Public Shared Sub Main()
        ' creates the CspParameters object and sets the key container name used to store the RSA key pair
        Dim cp As New CspParameters()
        cp.KeyContainerName = "MyKeyContainerName"
        
        ' instantiates the rsa instance accessing the key container MyKeyContainerName
        Dim rsa As New RSACryptoServiceProvider(cp)
        ' add the below line to delete the key entry in MyKeyContainerName
        ' rsa.PersistKeyInCsp = false;
        'writes out the current key pair used in the rsa instance
        Console.WriteLine("Key is : "  & rsa.ToXmlString(True))
    End Sub 'Main
End Class 'StoreKey

[C#] 
using System;
using System.IO;
using System.Security.Cryptography;

public class StoreKey
{
    public static void Main()
    {
        // creates the CspParameters object and sets the key container name used to store the RSA key pair
        CspParameters cp = new CspParameters();
        cp.KeyContainerName = "MyKeyContainerName";

        // instantiates the rsa instance accessing the key container MyKeyContainerName
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
        // add the below line to delete the key entry in MyKeyContainerName
        // rsa.PersistKeyInCsp = false;

        //writes out the current key pair used in the rsa instance
        Console.WriteLine("Key is : \n" + rsa.ToXmlString(true));
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;

int main()
{
    // creates the CspParameters object and sets the key container name used to store the RSA key pair
    CspParameters* cp = new CspParameters();
    cp->KeyContainerName = S"MyKeyContainerName";

    // instantiates the rsa instance accessing the key container MyKeyContainerName
    RSACryptoServiceProvider* rsa = new RSACryptoServiceProvider(cp);
    // add the below line to delete the key entry in MyKeyContainerName
    // rsa.PersistKeyInCsp = false;

    //writes out the current key pair used in the rsa instance
    Console::WriteLine(S"Key is : \n{0}", rsa->ToXmlString(true));
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

CspParameters Class | CspParameters Members | System.Security.Cryptography Namespace | Cryptographic Services

Show: