CspParameters.KeyContainerName Campo
Definição
Representa o nome do contêiner de chave de CspParameters.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
Valor do campo
Exemplos
O exemplo de código a seguir cria um contêiner de chave usando a CspParameters classe e salva a chave no contêiner.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
Comentários
Use o KeyContainerName campo para especificar um nome para o contêiner de chave.Use the KeyContainerName field to specify a name for your key container. Você pode usar o nome do contêiner para recuperar a chave persistente dentro desse contêiner.You can use the container name to retrieve the persisted key within that container.
Para obter mais informações sobre como criar contêineres de chave, consulte como armazenar chaves assimétricas em um contêiner de chave.For more information about creating key containers, see How to: Store Asymmetric Keys in a Key Container.