CspParameters.KeyContainerName Champ

Définition

Représente le nom du conteneur de clé pour CspParameters.Represents the key container name for CspParameters.

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

Valeur de champ

Exemples

L’exemple de code suivant crée un conteneur de clé CspParameters à l’aide de la classe et enregistre la clé dans le conteneur.The following code example creates a key container using the CspParameters class and saves the key in the container.

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 = gcnew CspParameters;
   cp->KeyContainerName = "MyKeyContainerName";
   
   // instantiates the rsa instance accessing the key container MyKeyContainerName
   RSACryptoServiceProvider^ rsa = gcnew 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{0}", rsa->ToXmlString( true ) );
}

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

Remarques

Utilisez le KeyContainerName champ pour spécifier un nom pour votre conteneur de clé.Use the KeyContainerName field to specify a name for your key container. Vous pouvez utiliser le nom du conteneur pour récupérer la clé rendue persistante dans ce conteneur.You can use the container name to retrieve the persisted key within that container.

Pour plus d’informations sur la création de conteneurs de clé, consultez Procédure: Stocker les clés asymétriques dans unconteneur de clé.For more information about creating key containers, see How to: Store Asymmetric Keys in a Key Container.

S’applique à

Voir aussi