Freigeben über


CspParameters.KeyContainerName Feld

Definition

Stellt den Schlüsselcontainernamen für CspParameters dar.

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

Feldwert

Beispiele

Im folgenden Codebeispiel wird ein Schlüsselcontainer mithilfe der CspParameters -Klasse erstellt und der Schlüssel im Container gespeichert.

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

Hinweise

Verwenden Sie das KeyContainerName Feld, um einen Namen für Ihren Schlüsselcontainer anzugeben. Sie können den Containernamen verwenden, um den persistenten Schlüssel in diesem Container abzurufen.

Weitere Informationen zum Erstellen von Schlüsselcontainern finden Sie unter Gewusst wie: Speichern von asymmetrischen Schlüsseln in einem Schlüsselcontainer.

Gilt für:

Weitere Informationen