Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

CspParameters.KeyContainerName Field

Definition

Namespace:
System.Security.Cryptography
Assemblies:
netstandard.dll, System.Security.Cryptography.dll
Assemblies:
netstandard.dll, System.Security.Cryptography.Csp.dll
Assemblies:
netstandard.dll, System.Security.Cryptography.dll, System.Security.Cryptography.Csp.dll
Assembly:
System.Security.Cryptography.Csp.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs
Source:
CspParameters.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents the key container name for CspParameters.

public: System::String ^ KeyContainerName;
public string? KeyContainerName;
public string KeyContainerName;
val mutable KeyContainerName : string
Public KeyContainerName As String 

Field Value

Examples

The following code example creates a key container using the CspParameters class and saves the key in the container.

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));
 }
}
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
End Class

Remarks

Use the KeyContainerName field to specify a name for your key container. You can use the container name to retrieve the persisted key within that container.

For more information about creating key containers, see How to: Store Asymmetric Keys in a Key Container.

Applies to

See also


Feedback

Was this page helpful?